Skip to content

Commit

Permalink
Use ShorthandSerializer for grid-template shorthand.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260397.
rdar://114097919.

Reviewed by Darin Adler.

The ShorthandSerializer already serializes the shorthand into its
shortest representation. When we get the property value for the computed
style, we can use the ShorthandSerializer instead.

In order to do this, the ShorthandSeralizer needs a new constructor that
can take a ComputedStyleExtractor. This will be used in commonSerializationChecks
to set the longhand values appropriately.

* LayoutTests/imported/w3c/web-platform-tests/css/css-grid/grid-layout-properties-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-getPropertyValue-common-checks-expected.txt:
* Source/WebCore/css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::getPropertyValue const):
* Source/WebCore/css/ShorthandSerializer.cpp:
(WebCore::ShorthandSerializer::ShorthandSerializer):
(WebCore::ShorthandSerializer::commonSerializationChecks):
(WebCore::serializeShorthandValue):
* Source/WebCore/css/ShorthandSerializer.h:

Canonical link: https://commits.webkit.org/267280@main
  • Loading branch information
sammygill committed Aug 25, 2023
1 parent ee5de7a commit 4820e6a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ PASS grid-template-areas.none
PASS grid-template-areas.<string>+
PASS grid-template-areas.reset
PASS grid-template
FAIL grid-template.initial assert_equals: initial value of grid-template should be 50px 50px 50px / 150px expected "50px 50px 50px / 150px" but got "50px 50px 50px / 150px / none"
FAIL grid-template.none assert_equals: none expected "50px 50px 50px / 150px" but got "50px 50px 50px / 150px / none"
FAIL grid-template.<grid-template-rows> / <grid-template-columns> assert_equals: <grid-template-rows> / <grid-template-columns> expected "100px 100px / 200px 200px" but got "100px 100px / 200px 200px / none"
FAIL grid-template.<line-names> assert_equals: <line-names> expected "[a] auto [b] auto [c] / [d] auto [e] auto [f]" but got "[a] 50px [b] 50px [c] / [d] 150px [e] 100px [f] / none"
FAIL grid-template.<string>+ assert_equals: <string>+ expected "\"a b\" \"a b\"" but got "50px 50px / 150px 100px / \"a b\" \"a b\""
PASS grid-template.initial
PASS grid-template.none
PASS grid-template.<grid-template-rows> / <grid-template-columns>
FAIL grid-template.<line-names> assert_equals: <line-names> expected "[a] auto [b] auto [c] / [d] auto [e] auto [f]" but got "[a] 50px [b] 50px [c] / [d] 150px [e] 100px [f]"
FAIL grid-template.<string>+ assert_equals: <string>+ expected "\"a b\" \"a b\"" but got "\"a b\" 50px \"a b\" 50px / 150px 100px"
FAIL grid-template.<string><track-size>+ assert_equals: <string><track-size>+ expected "100px / \"a b\" 50px" but got "\"a b\" \"a b\""
FAIL grid-template.reset assert_equals: reset expected "50px 50px 50px / 150px" but got "50px 50px 50px / 150px / none"
PASS grid-template.reset
PASS grid-auto-columns
PASS grid-auto-columns.initial
PASS grid-auto-columns.<track-size>.auto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS All properties can serialize 'initial'
FAIL All properties (except 'all') can serialize their initial value (computed) assert_array_equals: lengths differ, expected array [] length 0, got [["-webkit-line-clamp", "none"], ["-webkit-mask", ""], ["-webkit-perspective-origin-x", ""], ["-webkit-perspective-origin-y", ""], ["-webkit-text-stroke", ""], ["-webkit-transform-origin-x", ""], ["-webkit-transform-origin-y", ""], ["-webkit-transform-origin-z", ""], ["grid", "none / none / none / row / auto / auto"], ["grid-template", "none / none / none"], ["marker", ""], ["orphans", "auto"], ["page", ""], ["perspective-origin-x", ""], ["perspective-origin-y", ""], ["size", ""], ["text-box-edge", "leading leading"], ["transform-origin-x", ""], ["transform-origin-y", ""], ["transform-origin-z", ""], ["widows", "auto"]] length 21
FAIL All properties (except 'all') can serialize their initial value (computed) assert_array_equals: lengths differ, expected array [] length 0, got [["-webkit-line-clamp", "none"], ["-webkit-mask", ""], ["-webkit-perspective-origin-x", ""], ["-webkit-perspective-origin-y", ""], ["-webkit-text-stroke", ""], ["-webkit-transform-origin-x", ""], ["-webkit-transform-origin-y", ""], ["-webkit-transform-origin-z", ""], ["grid", "none / none / none / row / auto / auto"], ["marker", ""], ["orphans", "auto"], ["page", ""], ["perspective-origin-x", ""], ["perspective-origin-y", ""], ["size", ""], ["text-box-edge", "leading leading"], ["transform-origin-x", ""], ["transform-origin-y", ""], ["transform-origin-z", ""], ["widows", "auto"]] length 20
PASS All properties (except 'all') can serialize their initial value (specified)
FAIL All shorthands can serialize their longhands set to 'initial' assert_array_equals: lengths differ, expected array [] length 0, got [["all", ""]] length 1
PASS All shorthands (except 'all') can serialize their longhands set to their initial value
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "RenderBox.h"
#include "RenderBoxModelObject.h"
#include "RenderStyleInlines.h"
#include "ShorthandSerializer.h"
#include "StylePropertiesInlines.h"
#include "StylePropertyShorthand.h"
#include "StyleScope.h"
Expand Down Expand Up @@ -105,6 +106,17 @@ const FixedVector<CSSPropertyID>& CSSComputedStyleDeclaration::exposedComputedCS

String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) const
{
auto canUseShorthandSerializerForPropertyValue = [&]() {
switch (propertyID) {
case CSSPropertyGridTemplate:
return true;
default:
return false;
}
};
if (isShorthand(propertyID) && canUseShorthandSerializerForPropertyValue())
return serializeShorthandValue({ m_element.ptr(), m_allowVisitedStyle, m_pseudoElementSpecifier }, propertyID);

auto value = getPropertyCSSValue(propertyID);
if (!value)
return emptyString(); // FIXME: Should this be null instead, as it is in StyleProperties::getPropertyValue?
Expand Down
24 changes: 22 additions & 2 deletions Source/WebCore/css/ShorthandSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "CSSValueKeywords.h"
#include "CSSValuePair.h"
#include "CSSVariableReferenceValue.h"
#include "ComputedStyleExtractor.h"
#include "FontSelectionValueInlines.h"
#include "Quad.h"
#include "StylePropertiesInlines.h"
Expand All @@ -45,7 +46,7 @@ constexpr unsigned maxShorthandLength = 17; // FIXME: Generate this from CSSProp

class ShorthandSerializer {
public:
explicit ShorthandSerializer(const StyleProperties&, CSSPropertyID shorthandID);
template<typename PropertiesType> explicit ShorthandSerializer(const PropertiesType&, CSSPropertyID shorthandID);
String serialize();

private:
Expand Down Expand Up @@ -93,6 +94,7 @@ class ShorthandSerializer {

bool subsequentLonghandsHaveInitialValues(unsigned index) const;

bool commonSerializationChecks(const ComputedStyleExtractor&);
bool commonSerializationChecks(const StyleProperties&);

String serializeLonghands() const;
Expand Down Expand Up @@ -129,7 +131,8 @@ class ShorthandSerializer {
bool m_commonSerializationChecksSuppliedResult { false };
};

inline ShorthandSerializer::ShorthandSerializer(const StyleProperties& properties, CSSPropertyID shorthandID)
template<typename PropertiesType>
inline ShorthandSerializer::ShorthandSerializer(const PropertiesType& properties, CSSPropertyID shorthandID)
: m_shorthand(shorthandForProperty(shorthandID))
, m_commonSerializationChecksSuppliedResult(commonSerializationChecks(properties))
{
Expand Down Expand Up @@ -182,6 +185,18 @@ bool ShorthandSerializer::subsequentLonghandsHaveInitialValues(unsigned startInd
return true;
}

bool ShorthandSerializer::commonSerializationChecks(const ComputedStyleExtractor& properties)
{
ASSERT(length() && length() <= maxShorthandLength);

ASSERT(m_shorthand.id() != CSSPropertyAll);

for (unsigned i = 0; i < length(); ++i)
m_longhandValues[i] = properties.propertyValue(longhandProperty(i));

return false;
}

bool ShorthandSerializer::commonSerializationChecks(const StyleProperties& properties)
{
ASSERT(length());
Expand Down Expand Up @@ -1217,4 +1232,9 @@ String serializeShorthandValue(const StyleProperties& properties, CSSPropertyID
return ShorthandSerializer(properties, shorthand).serialize();
}

String serializeShorthandValue(const ComputedStyleExtractor& extractor, CSSPropertyID shorthand)
{
return ShorthandSerializer(extractor, shorthand).serialize();
}

}
2 changes: 2 additions & 0 deletions Source/WebCore/css/ShorthandSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

namespace WebCore {

class ComputedStyleExtractor;
class StyleProperties;

enum CSSPropertyID : uint16_t;

String serializeShorthandValue(const ComputedStyleExtractor&, CSSPropertyID);
String serializeShorthandValue(const StyleProperties&, CSSPropertyID);

}

0 comments on commit 4820e6a

Please sign in to comment.