711 // Set the axis we don't care about to be 1, since we want this overflow to always be considered reachable.
712 LayoutUnit rectWidth = 1_lu;
713 // For grid, width of the overflow rect should be the width of the grid area of the items rather than the container block.
714 // As per https://github.com/w3c/csswg-drafts/issues/3653, child's margins along with padding should contribute to the
715 // scrollable overflow area.
716 if (this->isRenderGrid())
717 rectWidth = clientLogicalRightAndBottomAfterRepositioning().width();
718
719 // When we have overflow clip, propagate the original spillout since it will include collapsed bottom margins
720 // and bottom padding.
721 LayoutRect clientRect(flippedClientBoxRect());
722 LayoutRect rectToApply;
723 if (isHorizontalWritingMode())
724 rectToApply = LayoutRect(clientRect.x(), clientRect.y(), rectWidth, std::max(0_lu, oldClientAfterEdge - clientRect.y()));
725 else
726 rectToApply = LayoutRect(clientRect.x(), clientRect.y(), std::max(0_lu, oldClientAfterEdge - clientRect.x()), rectWidth);
727 addLayoutOverflow(rectToApply);
694 auto includePaddingEnd = [&] {
695 // As per https://github.com/w3c/csswg-drafts/issues/3653 padding should contribute to the scrollable overflow area.
696 if (!paddingEnd())
697 return;
698 // FIXME: Expand it to non-grid cases when applicable.
699 if (!is<RenderGrid>(*this))
700 return;
701
702 auto layoutOverflowRect = this->layoutOverflowRect();
703 auto layoutOverflowLogicalWidthIncludingPaddingEnd = [&] {
704 if (hasHorizontalLayoutOverflow())
705 return (isHorizontalWritingMode() ? layoutOverflowRect.width() : layoutOverflowRect.height()) + paddingEnd();
706
707 // FIXME: This is not sufficient for BFC layout (missing non-formatting-context root descendants).
708 auto contentLogicalRight = LayoutUnit { };
709 for (auto& child : childrenOfType<RenderBox>(*this)) {
710 if (child.isOutOfFlowPositioned())
711 continue;
712 auto childLogicalRight = logicalLeftForChild(child) + logicalWidthForChild(child) + marginEndForChild(child);
713 contentLogicalRight = std::max(contentLogicalRight, childLogicalRight);
714 }
715 auto logicalRightWithPaddingEnd = contentLogicalRight + paddingEnd();
716 // Use padding box as the reference box.
717 return logicalRightWithPaddingEnd - (isHorizontalWritingMode() ? borderLeft() : borderTop());
718 };
719
720 if (isHorizontalWritingMode())
721 layoutOverflowRect.setWidth(layoutOverflowLogicalWidthIncludingPaddingEnd());
722 else
723 layoutOverflowRect.setHeight(layoutOverflowLogicalWidthIncludingPaddingEnd());
724 addLayoutOverflow(layoutOverflowRect);
725 };
726 includePaddingEnd();
727
728 auto includePaddingAfter = [&] {
729 // When we have overflow clip, propagate the original spillout since it will include collapsed bottom margins and bottom padding.
730 auto clientRect = flippedClientBoxRect();
731 auto rectToApply = clientRect;
732 // Set the axis we don't care about to be 1, since we want this overflow to always be considered reachable.
733 if (isHorizontalWritingMode()) {
734 rectToApply.setWidth(1);
735 rectToApply.setHeight(std::max(0_lu, oldClientAfterEdge - clientRect.y()));
736 } else {
737 rectToApply.setWidth(std::max(0_lu, oldClientAfterEdge - clientRect.x()));
738 rectToApply.setHeight(1);
739 }
740 addLayoutOverflow(rectToApply);
741 };
742 includePaddingAfter();