⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276548 in webkit


Ignore:
Timestamp:
Apr 24, 2021, 6:10:44 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC] Ignore content height and width when 'contain: size' is present
https://bugs.webkit.org/show_bug.cgi?id=225013

Reviewed by Antti Koivisto.

Enable size containment for "shrink to fit width" and for "height: auto" formatting context roots.
https://www.w3.org/TR/css-contain-2/#size-containment.

  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
(WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r276547 r276548  
     12021-04-24  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Ignore content height and width when 'contain: size' is present
     4        https://bugs.webkit.org/show_bug.cgi?id=225013
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Enable size containment for "shrink to fit width" and for "height: auto" formatting context roots.   
     9        https://www.w3.org/TR/css-contain-2/#size-containment.
     10
     11        * layout/FormattingContextGeometry.cpp:
     12        (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const):
     13        (WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth):
     14
    1152021-04-24  Rob Buis  <rbuis@igalia.com>
    216
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r271085 r276548  
    176176    ASSERT(formattingContextRoot.establishesFormattingContext());
    177177    ASSERT(isHeightAuto(formattingContextRoot) || formattingContextRoot.establishesTableFormattingContext() || formattingContextRoot.isTableCell());
    178     if (!formattingContextRoot.hasInFlowOrFloatingChild())
    179         return { };
    180     return LayoutContext::createFormattingContext(formattingContextRoot, const_cast<LayoutState&>(layoutState()))->usedContentHeight();
     178    auto usedContentHeight = LayoutUnit { };
     179    auto hasContent = formattingContextRoot.hasInFlowOrFloatingChild();
     180    // The used height of the containment box is determined as if performing a normal layout of the box, except that it is treated as having no content.
     181    auto shouldIgnoreContent = formattingContextRoot.isSizeContainmentBox();
     182    if (hasContent && !shouldIgnoreContent)
     183        usedContentHeight = LayoutContext::createFormattingContext(formattingContextRoot, const_cast<LayoutState&>(layoutState()))->usedContentHeight();
     184    return usedContentHeight;
    181185}
    182186
     
    279283}
    280284
    281 LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingRoot, LayoutUnit availableWidth)
    282 {
    283     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width] -> shrink to fit -> unsupported -> width(" << LayoutUnit { } << "px) layoutBox: " << &formattingRoot << ")");
    284     ASSERT(formattingRoot.establishesFormattingContext());
     285LayoutUnit FormattingContext::Geometry::shrinkToFitWidth(const Box& formattingContextRoot, LayoutUnit availableWidth)
     286{
     287    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width] -> shrink to fit -> unsupported -> width(" << LayoutUnit { } << "px) layoutBox: " << &formattingContextRoot << ")");
     288    ASSERT(formattingContextRoot.establishesFormattingContext());
    285289
    286290    // Calculation of the shrink-to-fit width is similar to calculating the width of a table cell using the automatic table layout algorithm.
     
    292296    // Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
    293297    auto intrinsicWidthConstraints = IntrinsicWidthConstraints { };
    294     if (is<ContainerBox>(formattingRoot) && downcast<ContainerBox>(formattingRoot).hasInFlowOrFloatingChild()) {
    295         auto& root = downcast<ContainerBox>(formattingRoot);
     298    auto hasContent = is<ContainerBox>(formattingContextRoot) && downcast<ContainerBox>(formattingContextRoot).hasInFlowOrFloatingChild();
     299    // The used width of the containment box is determined as if performing a normal layout of the box, except that it is treated as having no content.
     300    auto shouldIgnoreContent = formattingContextRoot.isSizeContainmentBox(); 
     301    if (hasContent && !shouldIgnoreContent) {
     302        auto& root = downcast<ContainerBox>(formattingContextRoot);
    296303        auto& formattingStateForRoot = layoutState().ensureFormattingState(root);
    297304        auto precomputedIntrinsicWidthConstraints = formattingStateForRoot.intrinsicWidthConstraints();
Note: See TracChangeset for help on using the changeset viewer.