getContainingBlockElement method
Implementation
Element? getContainingBlockElement({CSSPositionType? positionType}) {
Element? containingBlockElement;
positionType ??= renderStyle.position;
switch (positionType) {
case CSSPositionType.relative:
case CSSPositionType.static:
case CSSPositionType.sticky:
containingBlockElement = parentElement;
break;
case CSSPositionType.absolute:
Element viewportElement = ownerDocument.documentElement!;
// If the element has 'position: absolute', the containing block is established by the nearest ancestor with
// a 'position' of 'absolute', 'relative' or 'fixed', in the following way:
// 1. In the case that the ancestor is an inline element, the containing block is the bounding box around
// the padding boxes of the first and the last inline boxes generated for that element.
// In CSS 2.1, if the inline element is split across multiple lines, the containing block is undefined.
// 2. Otherwise, the containing block is formed by the padding edge of the ancestor.
containingBlockElement = _findContainingBlock(this, viewportElement);
break;
case CSSPositionType.fixed:
Element viewportElement = ownerDocument.documentElement!;
// If the element has 'position: fixed', the router link element was behavior as the HTMLElement in DOM mode.
containingBlockElement =
_findRouterLinkElement(this) ?? viewportElement;
break;
}
return containingBlockElement;
}