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

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: 4.7 KB
Line 
1/*
2 Copyright (C) 1999 Lars Knoll ([email protected])
3 Copyright (C) 2006, 2008 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#include "config.h"
25#include "LengthFunctions.h"
26
27#include "FloatSize.h"
28#include "LayoutSize.h"
29#include "LengthPoint.h"
30#include "LengthSize.h"
31
32namespace WebCore {
33
34int intValueForLength(const Length& length, LayoutUnit maximumValue)
35{
36 return static_cast<int>(valueForLength(length, maximumValue));
37}
38
39LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue)
40{
41 switch (length.type()) {
42 case LengthType::Fixed:
43 case LengthType::Percent:
44 case LengthType::Calculated:
45 return minimumValueForLength(length, maximumValue);
46 case LengthType::FillAvailable:
47 case LengthType::Auto:
48 return maximumValue;
49 case LengthType::Relative:
50 case LengthType::Intrinsic:
51 case LengthType::MinIntrinsic:
52 case LengthType::Content:
53 case LengthType::MinContent:
54 case LengthType::MaxContent:
55 case LengthType::FitContent:
56 case LengthType::Undefined:
57 ASSERT_NOT_REACHED();
58 return 0;
59 }
60 ASSERT_NOT_REACHED();
61 return 0;
62}
63
64// FIXME: when subpixel layout is supported this copy of floatValueForLength() can be removed. See bug 71143.
65float floatValueForLength(const Length& length, LayoutUnit maximumValue)
66{
67 switch (length.type()) {
68 case LengthType::Fixed:
69 return length.value();
70 case LengthType::Percent:
71 return static_cast<float>(maximumValue * length.percent() / 100.0f);
72 case LengthType::FillAvailable:
73 case LengthType::Auto:
74 return static_cast<float>(maximumValue);
75 case LengthType::Calculated:
76 return length.nonNanCalculatedValue(maximumValue);
77 case LengthType::Relative:
78 case LengthType::Intrinsic:
79 case LengthType::MinIntrinsic:
80 case LengthType::Content:
81 case LengthType::MinContent:
82 case LengthType::MaxContent:
83 case LengthType::FitContent:
84 case LengthType::Undefined:
85 ASSERT_NOT_REACHED();
86 return 0;
87 }
88 ASSERT_NOT_REACHED();
89 return 0;
90}
91
92float floatValueForLength(const Length& length, float maximumValue)
93{
94 switch (length.type()) {
95 case LengthType::Fixed:
96 return length.value();
97 case LengthType::Percent:
98 return static_cast<float>(maximumValue * length.percent() / 100.0f);
99 case LengthType::FillAvailable:
100 case LengthType::Auto:
101 return static_cast<float>(maximumValue);
102 case LengthType::Calculated:
103 return length.nonNanCalculatedValue(maximumValue);
104 case LengthType::Relative:
105 case LengthType::Intrinsic:
106 case LengthType::MinIntrinsic:
107 case LengthType::Content:
108 case LengthType::MinContent:
109 case LengthType::MaxContent:
110 case LengthType::FitContent:
111 case LengthType::Undefined:
112 ASSERT_NOT_REACHED();
113 return 0;
114 }
115 ASSERT_NOT_REACHED();
116 return 0;
117}
118
119LayoutSize sizeForLengthSize(const LengthSize& length, const LayoutSize& maximumValue)
120{
121 return { valueForLength(length.width, maximumValue.width()), valueForLength(length.height, maximumValue.height()) };
122}
123
124LayoutPoint pointForLengthPoint(const LengthPoint& lengthPoint, const LayoutSize& maximumValue)
125{
126 return { valueForLength(lengthPoint.x(), maximumValue.width()), valueForLength(lengthPoint.y(), maximumValue.height()) };
127}
128
129FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatSize& boxSize)
130{
131 return { floatValueForLength(lengthSize.width, boxSize.width()), floatValueForLength(lengthSize.height, boxSize.height()) };
132}
133
134FloatPoint floatPointForLengthPoint(const LengthPoint& lengthPoint, const FloatSize& boxSize)
135{
136 return { floatValueForLength(lengthPoint.x(), boxSize.width()), floatValueForLength(lengthPoint.y(), boxSize.height()) };
137}
138
139} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.