source: webkit/trunk/Source/WebCore/css/LengthFunctions.h

Last change on this file was 285709, checked in by [email protected], 4 years ago

[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.
File size: 3.3 KB
Line 
1/*
2 Copyright (C) 1999 Lars Knoll ([email protected])
3 Copyright (C) 2006-2017 Apple Inc. All rights reserved.
4 Copyright (C) 2011 Rik Cabanier ([email protected])
5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
6 Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24#pragma once
25
26#include "LayoutUnit.h"
27#include "Length.h"
28
29namespace WebCore {
30
31class FloatSize;
32class FloatPoint;
33class LayoutSize;
34
35struct Length;
36struct LengthSize;
37struct LengthPoint;
38
39int intValueForLength(const Length&, LayoutUnit maximumValue);
40float floatValueForLength(const Length&, LayoutUnit maximumValue);
41WEBCORE_EXPORT float floatValueForLength(const Length&, float maximumValue);
42WEBCORE_EXPORT LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue);
43
44LayoutSize sizeForLengthSize(const LengthSize&, const LayoutSize& maximumValue);
45FloatSize floatSizeForLengthSize(const LengthSize&, const FloatSize& maximumValue);
46
47LayoutPoint pointForLengthPoint(const LengthPoint&, const LayoutSize& maximumValue);
48FloatPoint floatPointForLengthPoint(const LengthPoint&, const FloatSize& maximumValue);
49
50inline LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue)
51{
52 switch (length.type()) {
53 case LengthType::Fixed:
54 return LayoutUnit(length.value());
55 case LengthType::Percent:
56 // Don't remove the extra cast to float. It is needed for rounding on 32-bit Intel machines that use the FPU stack.
57 return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f));
58 case LengthType::Calculated:
59 return LayoutUnit(length.nonNanCalculatedValue(maximumValue));
60 case LengthType::FillAvailable:
61 case LengthType::Auto:
62 case LengthType::Content:
63 return 0;
64 case LengthType::Relative:
65 case LengthType::Intrinsic:
66 case LengthType::MinIntrinsic:
67 case LengthType::MinContent:
68 case LengthType::MaxContent:
69 case LengthType::FitContent:
70 case LengthType::Undefined:
71 break;
72 }
73 ASSERT_NOT_REACHED();
74 return 0;
75}
76
77inline int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue)
78{
79 return static_cast<int>(minimumValueForLength(length, maximumValue));
80}
81
82template<typename T> inline LayoutUnit valueForLength(const Length& length, T maximumValue) { return valueForLength(length, LayoutUnit(maximumValue)); }
83template<typename T> inline LayoutUnit minimumValueForLength(const Length& length, T maximumValue) { return minimumValueForLength(length, LayoutUnit(maximumValue)); }
84
85} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.