scrollableElement.ts 5.9 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import {IScrollable} from 'vs/base/common/scrollable';

A
Alex Dima 已提交
9
export interface IScrollableElementCreationOptions {
E
Erich Gamma 已提交
10 11 12 13 14 15 16 17
	/**
	 * Prevent the scrollbar rendering from using translate3d. Defaults to false.
	 */
	forbidTranslate3dUse?: boolean;

	/**
	 * CSS Class name for the scrollable element.
	 */
A
Alex Dima 已提交
18
	className?: string;
E
Erich Gamma 已提交
19 20 21 22 23

	/**
	 * Drop subtle horizontal and vertical shadows.
	 * Defaults to false.
	 */
A
Alex Dima 已提交
24
	useShadows?: boolean;
E
Erich Gamma 已提交
25 26 27 28 29

	/**
	 * Handle mouse wheel (listen to mouse wheel scrolling).
	 * Defaults to true
	 */
A
Alex Dima 已提交
30
	handleMouseWheel?: boolean;
E
Erich Gamma 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

	/**
	 * Flip axes. Treat vertical scrolling like horizontal and vice-versa.
	 * Defaults to false;
	 */
	flipAxes?: boolean;

	/**
	 * A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.
	 * Defaults to 1.
	 */
	mouseWheelScrollSensitivity?: number;

	/**
	 * Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right).
	 * Defaults to 11.
	 */
A
Alex Dima 已提交
48
	arrowSize?: number;
E
Erich Gamma 已提交
49 50 51 52 53

	/**
	 * The scrollable that will react to all the scrolling logic.
	 * If no scrollable is provided, a dom node scrollable will be created automatically.
	 */
A
Alex Dima 已提交
54
	scrollable?: IScrollable;
E
Erich Gamma 已提交
55 56 57 58 59

	/**
	 * The dom node events should be bound to.
	 * If no listenOnDomNode is provided, the dom node passed to the constructor will be used for event listening.
	 */
A
Alex Dima 已提交
60
	listenOnDomNode?: HTMLElement;
E
Erich Gamma 已提交
61 62 63 64 65 66

	/**
	 * Control the visibility of the horizontal scrollbar.
	 * Accepted values: 'auto' (on mouse over), 'visible' (always visible), 'hidden' (never visible)
	 * Defaults to 'auto'.
	 */
A
Alex Dima 已提交
67
	horizontal?: string;
E
Erich Gamma 已提交
68 69 70 71 72

	/**
	 * Height (in px) of the horizontal scrollbar.
	 * Defaults to 10.
	 */
A
Alex Dima 已提交
73
	horizontalScrollbarSize?: number;
E
Erich Gamma 已提交
74 75 76 77 78

	/**
	 * Height (in px) of the horizontal scrollbar slider.
	 * Defaults to `horizontalScrollbarSize`
	 */
A
Alex Dima 已提交
79
	horizontalSliderSize?: number;
E
Erich Gamma 已提交
80 81 82 83 84

	/**
	 * Render arrows (left/right) for the horizontal scrollbar.
	 * Defaults to false.
	 */
A
Alex Dima 已提交
85
	horizontalHasArrows?: boolean;
E
Erich Gamma 已提交
86 87 88 89 90 91

	/**
	 * Control the visibility of the vertical scrollbar.
	 * Accepted values: 'auto' (on mouse over), 'visible' (always visible), 'hidden' (never visible)
	 * Defaults to 'auto'.
	 */
A
Alex Dima 已提交
92
	vertical?: string;
E
Erich Gamma 已提交
93 94 95 96 97

	/**
	 * Width (in px) of the vertical scrollbar.
	 * Defaults to 10.
	 */
A
Alex Dima 已提交
98
	verticalScrollbarSize?: number;
E
Erich Gamma 已提交
99 100 101 102 103

	/**
	 * Width (in px) of the vertical scrollbar slider.
	 * Defaults to `verticalScrollbarSize`
	 */
A
Alex Dima 已提交
104
	verticalSliderSize?: number;
E
Erich Gamma 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

	/**
	 * Render arrows (top/bottom) for the vertical scrollbar.
	 * Defaults to false.
	 */
	verticalHasArrows?: boolean;

	/**
	 * Add a `last-scroll-time` attribute to scroll targets or parents of scroll targets matching the following class name
	 */
	saveLastScrollTimeOnClassName?: string;
}

export interface IOverviewRulerLayoutInfo {
	parent: HTMLElement;
	insertBefore: HTMLElement;
}

export interface IDimensions {
	width: number;
	height: number;
}

/**
 * An Element that uses fancy scrollbars.
 */
export interface IScrollableElement {

A
Alex Dima 已提交
133
	verticalScrollbarWidth: number;
E
Erich Gamma 已提交
134

A
Alex Dima 已提交
135
	horizontalScrollbarHeight: number;
E
Erich Gamma 已提交
136 137 138 139

	/**
	 * Get the generated 'scrollable' dom node
	 */
A
Alex Dima 已提交
140
	getDomNode(): HTMLElement;
E
Erich Gamma 已提交
141 142 143 144

	/**
	 * Let the scrollable element know that the generated dom node's width / height might have changed.
	 */
A
Alex Dima 已提交
145
	onElementDimensions(dimensions?: IDimensions): void;
E
Erich Gamma 已提交
146 147 148 149 150 151 152

	/**
	 * Let the scrollable element know that the contained dom node's width / height might have changed.
	 */
	onElementInternalDimensions(): void;

	/**
A
Alex Dima 已提交
153
	 * Dispose.
E
Erich Gamma 已提交
154 155 156 157 158 159
	 */
	dispose(): void;

	/**
	 * Update the class name of the scrollable element.
	 */
A
Alex Dima 已提交
160
	updateClassName(newClassName: string): void;
E
Erich Gamma 已提交
161 162 163 164 165 166

	/**
	 * Update configuration options for the scrollbar.
	 * Really this is Editor.IEditorScrollbarOptions, but base shouldn't
	 * depend on Editor.
	 */
A
Alex Dima 已提交
167
	updateOptions(newOptions: IScrollableElementCreationOptions): void;
E
Erich Gamma 已提交
168

A
Alex Dima 已提交
169
	getOverviewRulerLayoutInfo(): IOverviewRulerLayoutInfo;
E
Erich Gamma 已提交
170 171 172 173 174

	/**
	 * Delegate a mouse down event to the vertical scrollbar.
	 * This is to help with clicking somewhere else and having the scrollbar react.
	 */
A
Alex Dima 已提交
175
	delegateVerticalScrollbarMouseDown(browserEvent: MouseEvent): void;
E
Erich Gamma 已提交
176

A
Alex Dima 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
}

export interface IMouseWheelEvent {
	browserEvent: MouseWheelEvent;
	deltaX: number;
	deltaY: number;
	preventDefault(): void;
	stopPropagation(): void;
}

export interface IScrollbar {
	domNode: HTMLElement;
	dispose(): void;
	slider: HTMLElement;
	onElementSize(size: number): void;
	onElementScrollSize(scrollSize: number): void;
	onElementScrollPosition(scrollPosition: number): void;
	beginReveal(): void;
	beginHide(): void;
	delegateMouseDown(browserEvent: MouseEvent): void;
	validateScrollPosition(scrollPosition: number): number;
	setDesiredScrollPosition(scrollPosition: number): void;
}

export interface IParent {
	onMouseWheel(mouseWheelEvent: IMouseWheelEvent): void;
	onDragStart(): void;
	onDragEnd(): void;
}

export enum Visibility {
	Auto,
	Hidden,
	Visible
A
tslint  
Alex Dima 已提交
211
}
A
Alex Dima 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

export function visibilityFromString(visibility: string): Visibility {
	switch (visibility) {
		case 'hidden':
			return Visibility.Hidden;
		case 'visible':
			return Visibility.Visible;
		default:
			return Visibility.Auto;
	}
}

export interface IScrollableElementOptions {
	forbidTranslate3dUse: boolean;
	className: string;
	useShadows: boolean;
	handleMouseWheel: boolean;
	flipAxes: boolean;
	mouseWheelScrollSensitivity: number;
	arrowSize: number;
	scrollable: IScrollable;
	listenOnDomNode: HTMLElement;
	horizontal: Visibility;
	horizontalScrollbarSize: number;
	horizontalSliderSize: number;
	horizontalHasArrows: boolean;
	vertical: Visibility;
	verticalScrollbarSize: number;
	verticalSliderSize: number;
	verticalHasArrows: boolean;
	saveLastScrollTimeOnClassName: string;
}