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

Changeset 285709 in webkit


Ignore:
Timestamp:
Nov 12, 2021, 2:17:21 AM (5 years ago)
Author:
svillar@igalia.com
Message:

[css-flexbox] Add flex-basis: content support
https://bugs.webkit.org/show_bug.cgi?id=221479

Reviewed by Javier Fernandez.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-flexbox/parsing/flex-basis-computed-expected.txt: Replaced FAIL

by PASS expectations.

  • web-platform-tests/css/css-flexbox/parsing/flex-basis-valid-expected.txt: Ditto.
  • web-platform-tests/css/css-flexbox/parsing/flex-shorthand-expected.txt: Ditto.

Source/WebCore:

Add support for the content keyword as a valid value for the flex-basis property.
It indicates an automated size based on the contents of the flex item. It's typically
equivalent to the max-content size but it has some adjustments for aspect ratios,
orthogonal flows and intrinsic sizing constraints.

Apart from adding the parsing support, it required very little adjustments in the
flexbox code after the refactoring in r284359.

This makes WebKit pass all of the flex-basis:content tests in WPT. We're talking
about 6 tests testing the feature and 6 subtests related to parsing.

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Handle Content in switch.
(WebCore::CSSPrimitiveValue::init): Initialization for content CSS value.

  • css/CSSProperties.json:
  • css/LengthFunctions.cpp: Replaced LengthOrAuto by LengthSizing.

(WebCore::valueForLength): Handle Content in switch.
(WebCore::floatValueForLength): Ditto.

  • css/LengthFunctions.h:

(WebCore::minimumValueForLength): Ditto.

  • css/calc/CSSCalcValue.cpp:

(WebCore::createCSS): Ditto.

  • css/parser/CSSPropertyParser.cpp:

(WebCore::consumeFlexBasis): Consume CSSValueContent.
(WebCore::CSSPropertyParser::consumeFlex): Ditto.

  • platform/Length.cpp:

(WebCore::operator<<): Added printing support for content.

  • platform/Length.h:

(WebCore::Length::initialize): Added enum for content.
(WebCore::Length::isContent const): New method.

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computeReplacedLogicalWidthUsing const): Handle content in switch.

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::childMainSizeIsDefinite): Treat content as indefinite lenght.
(WebCore::RenderFlexibleBox::computeFlexBaseSizeForChild): Compute flex-basis using max-content
if flex-basis:content is specified.

  • style/StyleBuilderConverter.h:

(WebCore::Style::BuilderConverter::convertLengthSizing): Handle content in switch.

Source/WebKit:

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<Length>::encode): Handle content in switch.
(IPC::ArgumentCoder<Length>::decode): Ditto.

LayoutTests:

  • TestExpectations: Unskipped all the flexbox-flex-basis-content tests that work fine now.
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r285708 r285709  
     12021-11-11  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Add flex-basis: content support
     4        https://bugs.webkit.org/show_bug.cgi?id=221479
     5
     6        Reviewed by Javier Fernandez.
     7
     8        * TestExpectations: Unskipped all the flexbox-flex-basis-content tests that work fine now.
     9
    1102021-11-12  Arcady Goldmints-Orlov  <agoldmints@igalia.com>
    211
  • trunk/LayoutTests/TestExpectations

    r285624 r285709  
    42624262webkit.org/b/221478 imported/w3c/web-platform-tests/css/css-flexbox/synthesize-vrl-baseline.html [ ImageOnlyFailure ]
    42634263
    4264 # flex-basis:content.
    4265 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-001a.html [ ImageOnlyFailure ]
    4266 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-001b.html [ ImageOnlyFailure ]
    4267 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-002a.html [ ImageOnlyFailure ]
    4268 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-002b.html [ ImageOnlyFailure ]
    4269 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-003a.html [ ImageOnlyFailure ]
    4270 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-004a.html [ ImageOnlyFailure ]
    4271 
    42724264# Flex item's min|max content contributions
    42734265webkit.org/b/230747 imported/w3c/web-platform-tests/css/css-flexbox/flex-container-max-content-001.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r285639 r285709  
     12021-11-11  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Add flex-basis: content support
     4        https://bugs.webkit.org/show_bug.cgi?id=221479
     5
     6        Reviewed by Javier Fernandez.
     7
     8        * web-platform-tests/css/css-flexbox/parsing/flex-basis-computed-expected.txt: Replaced FAIL
     9        by PASS expectations.
     10        * web-platform-tests/css/css-flexbox/parsing/flex-basis-valid-expected.txt: Ditto.
     11        * web-platform-tests/css/css-flexbox/parsing/flex-shorthand-expected.txt: Ditto.
     12
    1132021-11-11  Alexey Shvayka  <ashvayka@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/parsing/flex-basis-computed-expected.txt

    r285045 r285709  
    33PASS Property flex-basis value '400%'
    44PASS Property flex-basis value 'auto'
    5 FAIL Property flex-basis value 'content' assert_true: 'content' is a supported value for flex-basis. expected true got false
     5PASS Property flex-basis value 'content'
    66FAIL Property flex-basis value 'fit-content' assert_true: 'fit-content' is a supported value for flex-basis. expected true got false
    77FAIL Property flex-basis value 'min-content' assert_true: 'min-content' is a supported value for flex-basis. expected true got false
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/parsing/flex-basis-valid-expected.txt

    r285045 r285709  
    77FAIL e.style['flex-basis'] = "min-content" should set the property value assert_not_equals: property should be set got disallowed value ""
    88FAIL e.style['flex-basis'] = "max-content" should set the property value assert_not_equals: property should be set got disallowed value ""
    9 FAIL e.style['flex-basis'] = "content" should set the property value assert_not_equals: property should be set got disallowed value ""
     9PASS e.style['flex-basis'] = "content" should set the property value
    1010
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/parsing/flex-shorthand-expected.txt

    r285045 r285709  
    2424PASS e.style['flex'] = "8 auto" should set flex-shrink
    2525PASS e.style['flex'] = "8 auto" should not set unrelated longhands
    26 FAIL e.style['flex'] = "content" should set flex-basis assert_equals: flex-basis should be canonical expected "content" but got ""
    27 FAIL e.style['flex'] = "content" should set flex-grow assert_equals: flex-grow should be canonical expected "1" but got ""
    28 FAIL e.style['flex'] = "content" should set flex-shrink assert_equals: flex-shrink should be canonical expected "1" but got ""
    29 FAIL e.style['flex'] = "content" should not set unrelated longhands assert_true: expected true got false
     26PASS e.style['flex'] = "content" should set flex-basis
     27PASS e.style['flex'] = "content" should set flex-grow
     28PASS e.style['flex'] = "content" should set flex-shrink
     29PASS e.style['flex'] = "content" should not set unrelated longhands
    3030FAIL e.style['flex'] = "0 fit-content" should set flex-basis assert_equals: flex-basis should be canonical expected "fit-content" but got ""
    3131FAIL e.style['flex'] = "0 fit-content" should set flex-grow assert_equals: flex-grow should be canonical expected "0" but got ""
  • trunk/Source/WebCore/ChangeLog

    r285698 r285709  
     12021-11-11  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Add flex-basis: content support
     4        https://bugs.webkit.org/show_bug.cgi?id=221479
     5
     6        Reviewed by Javier Fernandez.
     7
     8        Add support for the content keyword as a valid value for the flex-basis property.
     9        It indicates an automated size based on the contents of the flex item. It's typically
     10        equivalent to the max-content size but it has some adjustments for aspect ratios,
     11        orthogonal flows and intrinsic sizing constraints.
     12
     13        Apart from adding the parsing support, it required very little adjustments in the
     14        flexbox code after the refactoring in r284359.
     15
     16        This makes WebKit pass all of the flex-basis:content tests in WPT. We're talking
     17        about 6 tests testing the feature and 6 subtests related to parsing.
     18
     19        * css/CSSPrimitiveValue.cpp:
     20        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Handle Content in switch.
     21        (WebCore::CSSPrimitiveValue::init): Initialization for content CSS value.
     22        * css/CSSProperties.json:
     23        * css/LengthFunctions.cpp: Replaced LengthOrAuto by LengthSizing.
     24        (WebCore::valueForLength): Handle Content in switch.
     25        (WebCore::floatValueForLength): Ditto.
     26        * css/LengthFunctions.h:
     27        (WebCore::minimumValueForLength): Ditto.
     28        * css/calc/CSSCalcValue.cpp:
     29        (WebCore::createCSS): Ditto.
     30        * css/parser/CSSPropertyParser.cpp:
     31        (WebCore::consumeFlexBasis): Consume CSSValueContent.
     32        (WebCore::CSSPropertyParser::consumeFlex): Ditto.
     33        * platform/Length.cpp:
     34        (WebCore::operator<<): Added printing support for content.
     35        * platform/Length.h:
     36        (WebCore::Length::initialize): Added enum for content.
     37        (WebCore::Length::isContent const): New method.
     38        * rendering/RenderBox.cpp:
     39        (WebCore::RenderBox::computeReplacedLogicalWidthUsing const): Handle content in switch.
     40        * rendering/RenderFlexibleBox.cpp:
     41        (WebCore::RenderFlexibleBox::childMainSizeIsDefinite): Treat content as indefinite lenght.
     42        (WebCore::RenderFlexibleBox::computeFlexBaseSizeForChild): Compute flex-basis using max-content
     43        if flex-basis:content is specified.
     44        * style/StyleBuilderConverter.h:
     45        (WebCore::Style::BuilderConverter::convertLengthSizing): Handle content in switch.
     46
    1472021-11-11  Brent Fulgham  <bfulgham@apple.com>
    248
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r285373 r285709  
    3939#include "DeprecatedCSSOMPrimitiveValue.h"
    4040#include "FontCascade.h"
     41#include "Length.h"
    4142#include "Node.h"
    4243#include "Pair.h"
     
    316317    switch (length.type()) {
    317318    case LengthType::Auto:
     319    case LengthType::Content:
    318320    case LengthType::Intrinsic:
    319321    case LengthType::MinIntrinsic:
     
    377379        setPrimitiveUnitType(CSSUnitType::CSS_VALUE_ID);
    378380        m_value.valueID = CSSValueAuto;
     381        return;
     382    case LengthType::Content:
     383        setPrimitiveUnitType(CSSUnitType::CSS_VALUE_ID);
     384        m_value.valueID = CSSValueContent;
    379385        return;
    380386    case LengthType::Fixed:
  • trunk/Source/WebCore/css/CSSProperties.json

    r285615 r285709  
    56345634                    "-webkit-flex-basis"
    56355635                ],
    5636                 "converter": "LengthOrAuto"
     5636                "converter": "LengthSizing"
    56375637            },
    56385638            "specification": {
  • trunk/Source/WebCore/css/LengthFunctions.cpp

    r285045 r285709  
    5050    case LengthType::Intrinsic:
    5151    case LengthType::MinIntrinsic:
     52    case LengthType::Content:
    5253    case LengthType::MinContent:
    5354    case LengthType::MaxContent:
     
    7778    case LengthType::Intrinsic:
    7879    case LengthType::MinIntrinsic:
     80    case LengthType::Content:
    7981    case LengthType::MinContent:
    8082    case LengthType::MaxContent:
     
    103105    case LengthType::Intrinsic:
    104106    case LengthType::MinIntrinsic:
     107    case LengthType::Content:
    105108    case LengthType::MinContent:
    106109    case LengthType::MaxContent:
  • trunk/Source/WebCore/css/LengthFunctions.h

    r285045 r285709  
    6060    case LengthType::FillAvailable:
    6161    case LengthType::Auto:
     62    case LengthType::Content:
    6263        return 0;
    6364    case LengthType::Relative:
  • trunk/Source/WebCore/css/calc/CSSCalcValue.cpp

    r285045 r285709  
    265265        return createCSS(length.calculationValue().expression(), style);
    266266    case LengthType::Auto:
     267    case LengthType::Content:
    267268    case LengthType::Intrinsic:
    268269    case LengthType::MinIntrinsic:
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r285492 r285709  
    22702270{
    22712271    // FIXME: Support intrinsic dimensions too.
    2272     if (range.peek().id() == CSSValueAuto)
     2272    if (range.peek().id() == CSSValueAuto || range.peek().id() == CSSValueContent)
    22732273        return consumeIdent(range);
    22742274    return consumeLengthOrPercent(range, cssParserMode, ValueRange::NonNegative);
     
    52695269                    return false;
    52705270            } else if (!flexBasis) {
    5271                 if (m_range.peek().id() == CSSValueAuto)
     5271                if (m_range.peek().id() == CSSValueAuto || m_range.peek().id() == CSSValueContent)
    52725272                    flexBasis = consumeIdent(m_range);
    52735273                if (!flexBasis)
  • trunk/Source/WebCore/platform/Length.cpp

    r285397 r285709  
    379379    case LengthType::FitContent: ts << "fit-content"; break;
    380380    case LengthType::Calculated: ts << "calc"; break;
     381    case LengthType::Content: ts << "content"; break;
    381382    case LengthType::Undefined: ts << "undefined"; break;
    382383    }
     
    388389    switch (length.type()) {
    389390    case LengthType::Auto:
     391    case LengthType::Content:
    390392    case LengthType::Undefined:
    391393        ts << length.type();
  • trunk/Source/WebCore/platform/Length.h

    r285045 r285709  
    4848    FitContent,
    4949    Calculated,
     50    Content,
    5051    Undefined
    5152};
     
    104105    bool isFitContent() const;
    105106    bool isMinIntrinsic() const;
     107    bool isContent() const;
    106108
    107109    bool hasQuirk() const;
     
    237239    switch (m_type) {
    238240    case LengthType::Auto:
     241    case LengthType::Content:
    239242    case LengthType::Undefined:
    240243        m_intValue = 0;
     
    269272    switch (m_type) {
    270273    case LengthType::Auto:
     274    case LengthType::Content:
    271275    case LengthType::Undefined:
    272276        m_intValue = 0;
     
    512516}
    513517
     518inline bool Length::isContent() const
     519{
     520    return type() == LengthType::Content;
     521}
     522
    514523Length convertTo100PercentMinusLength(const Length&);
    515524
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r285640 r285709  
    34043404    case LengthType::MinIntrinsic:
    34053405    case LengthType::Auto:
     3406    case LengthType::Content:
    34063407    case LengthType::Relative:
    34073408    case LengthType::Undefined:
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r285623 r285709  
    922922bool RenderFlexibleBox::childMainSizeIsDefinite(const RenderBox& child, const Length& flexBasis)
    923923{
    924     if (flexBasis.isAuto())
     924    if (flexBasis.isAuto() || flexBasis.isContent())
    925925        return false;
    926926    if (isColumnFlow() && (flexBasis.isIntrinsic() || flexBasis.type() == LengthType::Intrinsic))
     
    10301030{
    10311031    Length flexBasis = flexBasisForChild(child);
    1032     ScopedFlexBasisAsChildMainSize scoped(child, flexBasisForChild(child), mainAxisIsChildInlineAxis(child));
     1032    ScopedFlexBasisAsChildMainSize scoped(child, flexBasis.isContent() ? Length(LengthType::MaxContent) : flexBasis, mainAxisIsChildInlineAxis(child));
    10331033
    10341034    maybeCacheChildMainIntrinsicSize(child, relayoutChildren);
  • trunk/Source/WebCore/style/StyleBuilderConverter.h

    r285343 r285709  
    6969    static Length convertLength(const BuilderState&, const CSSValue&);
    7070    static Length convertLengthOrAuto(const BuilderState&, const CSSValue&);
     71    static Length convertLengthOrAutoOrContent(const BuilderState&, const CSSValue&);
    7172    static Length convertLengthSizing(const BuilderState&, const CSSValue&);
    7273    static Length convertLengthMaxSizing(const BuilderState&, const CSSValue&);
     
    245246    case CSSValueAuto:
    246247        return Length(LengthType::Auto);
     248    case CSSValueContent:
     249        return Length(LengthType::Content);
    247250    default:
    248251        ASSERT_NOT_REACHED();
  • trunk/Source/WebKit/ChangeLog

    r285707 r285709  
     12021-11-11  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Add flex-basis: content support
     4        https://bugs.webkit.org/show_bug.cgi?id=221479
     5
     6        Reviewed by Javier Fernandez.
     7
     8        * Shared/WebCoreArgumentCoders.cpp:
     9        (IPC::ArgumentCoder<Length>::encode): Handle content in switch.
     10        (IPC::ArgumentCoder<Length>::decode): Ditto.
     11
    1122021-11-11  Per Arne Vollan <pvollan@apple.com>
    213
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r285361 r285709  
    718718    switch (length.type()) {
    719719    case LengthType::Auto:
     720    case LengthType::Content:
    720721    case LengthType::Undefined:
    721722        break;
     
    753754    switch (type) {
    754755    case LengthType::Auto:
     756    case LengthType::Content:
    755757    case LengthType::Undefined:
    756758        length = Length(type);
Note: See TracChangeset for help on using the changeset viewer.