Skip to content

Commit e5d76d4

Browse files
committed
refactor(cdk/overlay): clarify usage of dimensions v.s. placement
u
1 parent 18cedc7 commit e5d76d4

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ export type FlexibleConnectedPositionStrategyOrigin =
4242
height?: number;
4343
});
4444

45-
/** Equivalent of `DOMRect` without some of the properties we don't care about. */
46-
type Dimensions = Omit<DOMRect, 'x' | 'y' | 'toJSON'>;
45+
/** Refinement of `DOMRect` when only width/height and position (l, r, t, b) are needed. */
46+
type Rect = Omit<DOMRect, 'x' | 'y' | 'toJSON'>;
47+
48+
/** Further refinement of above for when only the dimensions are needed. */
49+
type Dimensions = Omit<Rect, 'left' | 'top' | 'right' | 'bottom'>;
4750

4851
/**
4952
* Creates a flexible position strategy.
@@ -95,17 +98,17 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
9598
/** Whether the overlay position is locked. */
9699
private _positionLocked = false;
97100

98-
/** Cached origin dimensions */
99-
private _originRect: Dimensions;
101+
/** Cached origin placement and dimentsions. */
102+
private _originRect: Rect;
100103

101-
/** Cached overlay dimensions */
102-
private _overlayRect: Dimensions;
104+
/** Cached overlay placement and dimensions */
105+
private _overlayRect: Rect;
103106

104-
/** Cached viewport dimensions */
105-
private _viewportRect: Dimensions;
107+
/** Cached viewport placement and dimensions */
108+
private _viewportRect: Rect;
106109

107-
/** Cached container dimensions */
108-
private _containerRect: Dimensions;
110+
/** Cached container placement and dimensions */
111+
private _containerRect: Rect;
109112

110113
/** Amount of space that must be maintained between the overlay and the right edge of the viewport. */
111114
private _viewportMargin: ViewportMargin = 0;
@@ -514,11 +517,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
514517
/**
515518
* Gets the (x, y) coordinate of a connection point on the origin based on a relative position.
516519
*/
517-
private _getOriginPoint(
518-
originRect: Dimensions,
519-
containerRect: Dimensions,
520-
pos: ConnectedPosition,
521-
): Point {
520+
private _getOriginPoint(originRect: Rect, containerRect: Rect, pos: ConnectedPosition): Point {
522521
let x: number;
523522
if (pos.originX == 'center') {
524523
// Note: when centering we should always use the `left`
@@ -592,7 +591,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
592591
/** Gets how well an overlay at the given point will fit within the viewport. */
593592
private _getOverlayFit(
594593
point: Point,
595-
rawOverlayRect: Dimensions,
594+
rawOverlayRect: Rect,
596595
viewport: Dimensions,
597596
position: ConnectedPosition,
598597
): OverlayFit {
@@ -637,7 +636,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
637636
* @param point The (x, y) coordinates of the overlay at some position.
638637
* @param viewport The geometry of the viewport.
639638
*/
640-
private _canFitWithFlexibleDimensions(fit: OverlayFit, point: Point, viewport: Dimensions) {
639+
private _canFitWithFlexibleDimensions(fit: OverlayFit, point: Point, viewport: Rect) {
641640
if (this._hasFlexibleDimensions) {
642641
const availableHeight = viewport.bottom - point.y;
643642
const availableWidth = viewport.right - point.x;
@@ -667,7 +666,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
667666
*/
668667
private _pushOverlayOnScreen(
669668
start: Point,
670-
rawOverlayRect: Dimensions,
669+
rawOverlayRect: Rect,
671670
scrollPosition: ViewportScrollPosition,
672671
): Point {
673672
// If the position is locked and we've pushed the overlay already, reuse the previous push
@@ -1113,7 +1112,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
11131112
}
11141113

11151114
/** Narrows the given viewport rect by the current _viewportMargin. */
1116-
private _getNarrowedViewportRect(): Dimensions {
1115+
private _getNarrowedViewportRect(): Rect {
11171116
// We recalculate the viewport rect here ourselves, rather than using the ViewportRuler,
11181117
// because we want to use the `clientWidth` and `clientHeight` as the base. The difference
11191118
// being that the client properties don't include the scrollbar, as opposed to `innerWidth`
@@ -1231,7 +1230,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
12311230
}
12321231

12331232
/** Returns the DOMRect of the current origin. */
1234-
private _getOriginRect(): Dimensions {
1233+
private _getOriginRect(): Rect {
12351234
const origin = this._origin;
12361235

12371236
if (origin instanceof ElementRef) {
@@ -1353,7 +1352,7 @@ function getPixelValue(input: number | string | null | undefined): number | null
13531352
* deviations in the `DOMRect` returned by the browser (e.g. when zoomed in with a percentage
13541353
* size, see #21350).
13551354
*/
1356-
function getRoundedBoundingClientRect(clientRect: Dimensions): Dimensions {
1355+
function getRoundedBoundingClientRect(clientRect: Rect): Rect {
13571356
return {
13581357
top: Math.floor(clientRect.top),
13591358
right: Math.floor(clientRect.right),

0 commit comments

Comments
 (0)