From 78e0286f3414f1b1f6e4b231be6caa2b5e52ccee Mon Sep 17 00:00:00 2001 From: "jfernandez@igalia.com" Date: Wed, 5 Apr 2017 20:44:10 +0000 Subject: [PATCH] [css-align] Implement the place-items shorthand https://bugs.webkit.org/show_bug.cgi?id=168847 Reviewed by David Hyatt. Source/WebCore: The CSS Box Alignment specification defines a new shorthand to set the Content Alignment properties (align-items and justify-items) at the same time. This patch provides the implementation of the CSS parsing logic and the required regression tests. For the time being, as it happens with the rest of the new alignment properties, the new parsing logic is implemented behind the CSS Grid Layout runtime flag. Test: css3/parse-place-items.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::propertyValue): * css/CSSProperties.json: * css/StyleProperties.cpp: (WebCore::StyleProperties::getPropertyValue): (WebCore::StyleProperties::getAlignmentShorthandValue): * css/StyleProperties.h: * css/parser/CSSPropertyParser.cpp: (WebCore::isAutoOrNormalOrStretch): (WebCore::consumeSelfPositionOverflowPosition): (WebCore::consumeSimplifiedItemPosition): (WebCore::CSSPropertyParser::consumePlaceItemsShorthand): * css/parser/CSSPropertyParser.h: LayoutTests: Regression tests for the new place-content alignment shorthand. * css3/parse-place-items.html: Added. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214966 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 11 + LayoutTests/css3/parse-place-items-expected.txt | 28 +++ LayoutTests/css3/parse-place-items.html | 260 +++++++++++++++++++++ Source/WebCore/ChangeLog | 32 +++ Source/WebCore/css/CSSComputedStyleDeclaration.cpp | 3 + Source/WebCore/css/CSSProperties.json | 12 + Source/WebCore/css/StyleProperties.cpp | 10 +- Source/WebCore/css/StyleProperties.h | 2 +- Source/WebCore/css/parser/CSSPropertyParser.cpp | 44 +++- Source/WebCore/css/parser/CSSPropertyParser.h | 1 + 10 files changed, 397 insertions(+), 6 deletions(-) create mode 100644 LayoutTests/css3/parse-place-items-expected.txt create mode 100644 LayoutTests/css3/parse-place-items.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index b80c46a..b988f11 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2017-04-05 Javier Fernandez + + [css-align] Implement the place-items shorthand + https://bugs.webkit.org/show_bug.cgi?id=168847 + + Reviewed by David Hyatt. + + Regression tests for the new place-content alignment shorthand. + + * css3/parse-place-items.html: Added. + 2017-04-05 Carlos Alberto Lopez Perez [WebRTC][OpenWebRTC] Add support for SDP BUNDLE ("a:group:BUNDLE" and "a=bundle-only" lines) diff --git a/LayoutTests/css3/parse-place-items-expected.txt b/LayoutTests/css3/parse-place-items-expected.txt new file mode 100644 index 0000000..5363bc8 --- /dev/null +++ b/LayoutTests/css3/parse-place-items-expected.txt @@ -0,0 +1,28 @@ +Test to verify that the new place-items alignment shorthand is parsed as expected and correctly sets the longhand values. + + +PASS Test getting the Computed Value of place-items's longhand properties when setting 'normal' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'center auto' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'baseline' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'first baseline' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'last baseline' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'start' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'flex-start' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'end' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'self-start' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'stretch' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'start end' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'start self-end' value through CSS. +PASS Test getting the Computed Value of place-items's longhand properties when setting 'start baseline' value through CSS. +PASS Test setting '' as incorrect value through CSS. +PASS Test setting 'auto' as incorrect value through CSS. +PASS Test setting 'none' as incorrect value through CSS. +PASS Test setting 'safe' as incorrect value through CSS. +PASS Test setting 'start safe' as incorrect value through CSS. +PASS Test setting 'baseline safe' as incorrect value through CSS. +PASS Test setting 'start end left' as incorrect value through CSS. +PASS Test setting values through JS. +PASS Test setting incorrect values through JS. +PASS Test the 'initial' value of the place-items shorthand and its longhand properties' Computed value +PASS Test the 'inherit' value of the place-items shorthand and its longhand properties' Computed value + diff --git a/LayoutTests/css3/parse-place-items.html b/LayoutTests/css3/parse-place-items.html new file mode 100644 index 0000000..4ec8722 --- /dev/null +++ b/LayoutTests/css3/parse-place-items.html @@ -0,0 +1,260 @@ + + + + + + + + + +

Test to verify that the new place-items alignment shorthand is parsed as expected and correctly sets the longhand values.

+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index b199074..a24f57e 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,35 @@ +2017-04-05 Javier Fernandez + + [css-align] Implement the place-items shorthand + https://bugs.webkit.org/show_bug.cgi?id=168847 + + Reviewed by David Hyatt. + + The CSS Box Alignment specification defines a new shorthand to set the + Content Alignment properties (align-items and justify-items) at the + same time. + + This patch provides the implementation of the CSS parsing logic and the + required regression tests. For the time being, as it happens with the + rest of the new alignment properties, the new parsing logic is + implemented behind the CSS Grid Layout runtime flag. + + Test: css3/parse-place-items.html + + * css/CSSComputedStyleDeclaration.cpp: + (WebCore::ComputedStyleExtractor::propertyValue): + * css/CSSProperties.json: + * css/StyleProperties.cpp: + (WebCore::StyleProperties::getPropertyValue): + (WebCore::StyleProperties::getAlignmentShorthandValue): + * css/StyleProperties.h: + * css/parser/CSSPropertyParser.cpp: + (WebCore::isAutoOrNormalOrStretch): + (WebCore::consumeSelfPositionOverflowPosition): + (WebCore::consumeSimplifiedItemPosition): + (WebCore::CSSPropertyParser::consumePlaceItemsShorthand): + * css/parser/CSSPropertyParser.h: + 2017-04-05 Ryan Haddad Unreviewed, rolling out r214932. diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp index 7f8f79c..f9a9733 100644 --- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp +++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp @@ -327,6 +327,7 @@ static const CSSPropertyID computedProperties[] = { CSSPropertyJustifySelf, CSSPropertyJustifyItems, CSSPropertyPlaceContent, + CSSPropertyPlaceItems, #if ENABLE(FILTERS_LEVEL_2) CSSPropertyWebkitBackdropFilter, #endif @@ -2950,6 +2951,8 @@ RefPtr ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, return valueForItemPositionWithOverflowAlignment(resolveJustifySelfAuto(style->justifySelf(), styledElement->parentNode())); case CSSPropertyPlaceContent: return getCSSPropertyValuesForShorthandProperties(placeContentShorthand()); + case CSSPropertyPlaceItems: + return getCSSPropertyValuesForShorthandProperties(placeItemsShorthand()); case CSSPropertyOrder: return cssValuePool.createValue(style->order(), CSSPrimitiveValue::CSS_NUMBER); case CSSPropertyFloat: diff --git a/Source/WebCore/css/CSSProperties.json b/Source/WebCore/css/CSSProperties.json index b9d6992..37730b6 100644 --- a/Source/WebCore/css/CSSProperties.json +++ b/Source/WebCore/css/CSSProperties.json @@ -4677,6 +4677,18 @@ "url": "https://www.w3.org/TR/css-align-3/#propdef-place-content" } }, + "place-items": { + "codegen-properties": { + "longhands": [ + "align-items", + "justify-items" + ] + }, + "specification": { + "category": "css-align", + "url": "https://drafts.csswg.org/css-align-3/#propdef-place-items" + } + }, "grid": { "codegen-properties": { "longhands": [ diff --git a/Source/WebCore/css/StyleProperties.cpp b/Source/WebCore/css/StyleProperties.cpp index da1849a..a3a10a6 100644 --- a/Source/WebCore/css/StyleProperties.cpp +++ b/Source/WebCore/css/StyleProperties.cpp @@ -186,7 +186,9 @@ String StyleProperties::getPropertyValue(CSSPropertyID propertyID) const case CSSPropertyGridRow: return getShorthandValue(gridRowShorthand()); case CSSPropertyPlaceContent: - return placeContentPropertyValue(); + return getAlignmentShorthandValue(placeContentShorthand()); + case CSSPropertyPlaceItems: + return getAlignmentShorthandValue(placeItemsShorthand()); case CSSPropertyFont: return fontValue(); case CSSPropertyMargin: @@ -583,11 +585,11 @@ String StyleProperties::getCommonValue(const StylePropertyShorthand& shorthand) return res; } -String StyleProperties::placeContentPropertyValue() const +String StyleProperties::getAlignmentShorthandValue(const StylePropertyShorthand& shorthand) const { - String value = getCommonValue(placeContentShorthand()); + String value = getCommonValue(shorthand); if (value.isNull() || value.isEmpty()) - return getShorthandValue(placeContentShorthand()); + return getShorthandValue(shorthand); return value; } diff --git a/Source/WebCore/css/StyleProperties.h b/Source/WebCore/css/StyleProperties.h index 481fa79..fd9fca3 100644 --- a/Source/WebCore/css/StyleProperties.h +++ b/Source/WebCore/css/StyleProperties.h @@ -157,7 +157,7 @@ protected: private: String getShorthandValue(const StylePropertyShorthand&) const; String getCommonValue(const StylePropertyShorthand&) const; - String placeContentPropertyValue() const; + String getAlignmentShorthandValue(const StylePropertyShorthand&) const; enum CommonValueMode { OmitUncommonValues, ReturnNullOnUncommonValues }; String borderPropertyValue(CommonValueMode) const; String getLayeredShorthandValue(const StylePropertyShorthand&) const; diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp index f27455f..ceb3c8d 100644 --- a/Source/WebCore/css/parser/CSSPropertyParser.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp @@ -2619,6 +2619,11 @@ static RefPtr consumeShapeOutside(CSSParserTokenRange& range, const CS return list; } +static bool isAutoOrNormalOrStretch(CSSValueID id) +{ + return identMatches(id); +} + static bool isContentDistributionKeyword(CSSValueID id) { return identMatches(id); @@ -3075,7 +3080,7 @@ static RefPtr consumeSelfPositionKeyword(CSSParserTokenRange& static RefPtr consumeSelfPositionOverflowPosition(CSSParserTokenRange& range) { CSSValueID id = range.peek().id(); - if (identMatches(id)) + if (isAutoOrNormalOrStretch(id)) return consumeIdent(range); if (isBaselineKeyword(id)) @@ -5505,6 +5510,41 @@ bool CSSPropertyParser::consumePlaceContentShorthand(bool important) return true; } +static RefPtr consumeSimplifiedItemPosition(CSSParserTokenRange& range) +{ + CSSValueID id = range.peek().id(); + if (isAutoOrNormalOrStretch(id)) + return consumeIdent(range); + + if (isBaselineKeyword(id)) + return consumeBaselineKeyword(range); + + return consumeSelfPositionKeyword(range); +} + +bool CSSPropertyParser::consumePlaceItemsShorthand(bool important) +{ + ASSERT(shorthandForProperty(CSSPropertyPlaceItems).length() == 2); + + // align-items property does not allow the 'auto' value. + if (identMatches(m_range.peek().id())) + return false; + + RefPtr alignItemsValue = consumeSimplifiedItemPosition(m_range); + if (!alignItemsValue) + return false; + RefPtr justifyItemsValue = m_range.atEnd() ? alignItemsValue : consumeSimplifiedItemPosition(m_range); + if (!justifyItemsValue) + return false; + + if (!m_range.atEnd()) + return false; + + addProperty(CSSPropertyAlignItems, CSSPropertyPlaceItems, alignItemsValue.releaseNonNull(), important); + addProperty(CSSPropertyJustifyItems, CSSPropertyPlaceItems, justifyItemsValue.releaseNonNull(), important); + return true; +} + bool CSSPropertyParser::parseShorthand(CSSPropertyID property, bool important) { switch (property) { @@ -5688,6 +5728,8 @@ bool CSSPropertyParser::parseShorthand(CSSPropertyID property, bool important) return consumeGridShorthand(important); case CSSPropertyPlaceContent: return consumePlaceContentShorthand(important); + case CSSPropertyPlaceItems: + return consumePlaceItemsShorthand(important); case CSSPropertyWebkitMarquee: return consumeShorthandGreedily(webkitMarqueeShorthand(), important); default: diff --git a/Source/WebCore/css/parser/CSSPropertyParser.h b/Source/WebCore/css/parser/CSSPropertyParser.h index bdde19c..10269cd 100644 --- a/Source/WebCore/css/parser/CSSPropertyParser.h +++ b/Source/WebCore/css/parser/CSSPropertyParser.h @@ -81,6 +81,7 @@ private: bool consumeGridAreaShorthand(bool important); bool consumePlaceContentShorthand(bool important); + bool consumePlaceItemsShorthand(bool important); bool consumeFont(bool important); bool consumeFontVariantShorthand(bool important); -- 1.8.3.1