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/overlay/position/connected-position-strategy.js","sourcesContent":["import {PositionStrategy} from './position-strategy';\nimport {ElementRef} from '@angular/core';\nimport {ViewportRuler} from './viewport-ruler';\nimport {applyCssTransform} from '@angular2-material/core';\nimport {\n ConnectionPositionPair,\n OriginConnectionPosition,\n OverlayConnectionPosition\n} from './connected-position';\n\n\n/**\n * A strategy for positioning overlays. Using this strategy, an overlay is given an\n * implict position relative some origin element. The relative position is defined in terms of\n * a point on the origin element that is connected to a point on the overlay element. For example,\n * a basic dropdown is connecting the bottom-left corner of the origin to the top-left corner\n * of the overlay.\n */\nexport class ConnectedPositionStrategy implements PositionStrategy {\n // TODO(jelbourn): set RTL to the actual value from the app.\n /** Whether the we're dealing with an RTL context */\n _isRtl: boolean = false;\n\n /** Ordered list of preferred positions, from most to least desirable. */\n _preferredPositions: ConnectionPositionPair[] = [];\n\n /** The origin element against which the overlay will be positioned. */\n private _origin: HTMLElement;\n\n\n constructor(\n private _connectedTo: ElementRef,\n private _originPos: OriginConnectionPosition,\n private _overlayPos: OverlayConnectionPosition,\n private _viewportRuler: ViewportRuler) {\n this._origin = this._connectedTo.nativeElement;\n this.withFallbackPosition(_originPos, _overlayPos);\n }\n\n get positions() {\n return this._preferredPositions;\n }\n\n /**\n * Updates the position of the overlay element, using whichever preferred position relative\n * to the origin fits on-screen.\n * TODO: internal\n */\n apply(element: HTMLElement): Promise<void> {\n // We need the bounding rects for the origin and the overlay to determine how to position\n // the overlay relative to the origin.\n const originRect = this._origin.getBoundingClientRect();\n const overlayRect = element.getBoundingClientRect();\n\n // We use the viewport rect to determine whether a position would go off-screen.\n const viewportRect = this._viewportRuler.getViewportRect();\n let firstOverlayPoint: Point = null;\n\n // We want to place the overlay in the first of the preferred positions such that the\n // overlay fits on-screen.\n for (let pos of this._preferredPositions) {\n // Get the (x, y) point of connection on the origin, and then use that to get the\n // (top, left) coordinate for the overlay at `pos`.\n let originPoint = this._getOriginConnectionPoint(originRect, pos);\n let overlayPoint = this._getOverlayPoint(originPoint, overlayRect, pos);\n firstOverlayPoint = firstOverlayPoint || overlayPoint;\n\n // If the overlay in the calculated position fits on-screen, put it there and we're done.\n if (this._willOverlayFitWithinViewport(overlayPoint, overlayRect, viewportRect)) {\n this._setElementPosition(element, overlayPoint);\n return Promise.resolve(null);\n }\n }\n\n // TODO(jelbourn): fallback behavior for when none of the preferred positions fit on-screen.\n // For now, just stick it in the first position and let it go off-screen.\n this._setElementPosition(element, firstOverlayPoint);\n return Promise.resolve(null);\n }\n\n withFallbackPosition(\n originPos: OriginConnectionPosition,\n overlayPos: OverlayConnectionPosition): this {\n this._preferredPositions.push(new ConnectionPositionPair(originPos, overlayPos));\n return this;\n }\n\n\n /**\n * Gets the horizontal (x) \"start\" dimension based on whether the overlay is in an RTL context.\n * @param rect\n */\n private _getStartX(rect: ClientRect): number {\n return this._isRtl ? rect.right : rect.left;\n }\n\n /**\n * Gets the horizontal (x) \"end\" dimension based on whether the overlay is in an RTL context.\n * @param rect\n */\n private _getEndX(rect: ClientRect): number {\n return this._isRtl ? rect.left : rect.right;\n }\n\n\n /**\n * Gets the (x, y) coordinate of a connection point on the origin based on a relative position.\n * @param originRect\n * @param pos\n */\n private _getOriginConnectionPoint(originRect: ClientRect, pos: ConnectionPositionPair): Point {\n const originStartX = this._getStartX(originRect);\n const originEndX = this._getEndX(originRect);\n\n let x: number;\n if (pos.originX == 'center') {\n x = originStartX + (originRect.width / 2);\n } else {\n x = pos.originX == 'start' ? originStartX : originEndX;\n }\n\n let y: number;\n if (pos.originY == 'center') {\n y = originRect.top + (originRect.height / 2);\n } else {\n y = pos.originY == 'top' ? originRect.top : originRect.bottom;\n }\n\n return {x, y};\n }\n\n\n /**\n * Gets the (x, y) coordinate of the top-left corner of the overlay given a given position and\n * origin point to which the overlay should be connected.\n * @param originPoint\n * @param overlayRect\n * @param pos\n */\n private _getOverlayPoint(\n originPoint: Point,\n overlayRect: ClientRect,\n pos: ConnectionPositionPair): Point {\n // Calculate the (overlayStartX, overlayStartY), the start of the potential overlay position\n // relative to the origin point.\n let overlayStartX: number;\n if (pos.overlayX == 'center') {\n overlayStartX = -overlayRect.width / 2;\n } else {\n overlayStartX = pos.overlayX == 'start' ? 0 : -overlayRect.width;\n }\n\n let overlayStartY: number;\n if (pos.overlayY == 'center') {\n overlayStartY = -overlayRect.height / 2;\n } else {\n overlayStartY = pos.overlayY == 'top' ? 0 : -overlayRect.height;\n }\n\n return {\n x: originPoint.x + overlayStartX,\n y: originPoint.y + overlayStartY\n };\n }\n\n\n /**\n * Gets whether the overlay positioned at the given point will fit on-screen.\n * @param overlayPoint The top-left coordinate of the overlay.\n * @param overlayRect Bounding rect of the overlay, used to get its size.\n * @param viewportRect The bounding viewport.\n */\n private _willOverlayFitWithinViewport(\n overlayPoint: Point,\n overlayRect: ClientRect,\n viewportRect: ClientRect): boolean {\n\n // TODO(jelbourn): probably also want some space between overlay edge and viewport edge.\n return overlayPoint.x >= viewportRect.left &&\n overlayPoint.x + overlayRect.width <= viewportRect.right &&\n overlayPoint.y >= viewportRect.top &&\n overlayPoint.y + overlayRect.height <= viewportRect.bottom;\n }\n\n\n /**\n * Physically positions the overlay element to the given coordinate.\n * @param element\n * @param overlayPoint\n */\n private _setElementPosition(element: HTMLElement, overlayPoint: Point) {\n let scrollPos = this._viewportRuler.getViewportScrollPosition();\n\n let x = overlayPoint.x + scrollPos.left;\n let y = overlayPoint.y + scrollPos.top;\n\n // TODO(jelbourn): we don't want to always overwrite the transform property here,\n // because it will need to be used for animations.\n applyCssTransform(element, `translateX(${x}px) translateY(${y}px)`);\n }\n}\n\n\n/** A simple (x, y) coordinate. */\ntype Point = {x: number, y: number};\n\n\n"],"sourceRoot":"/source/"}
\No newline at end of file