[css-anchor-position-1] Implement parsing support for position-area#35202
[css-anchor-position-1] Implement parsing support for position-area#35202Scony wants to merge 1 commit intoWebKit:mainfrom
Conversation
42a58c7 to
66dc9d3
Compare
|
EWS run on previous version of this PR (hash 66dc9d3) Details |
nt1m
left a comment
There was a problem hiding this comment.
Usually we implement the internal representation + computed style representation at the same time as parsing, simply because these decisions influence how we parse.
Is it possible to do this here?
Yes, it's doable - let me add that part as well then. Converting to draft until I update the PR with computing support. |
66dc9d3 to
472cb69
Compare
|
EWS run on previous version of this PR (hash 472cb69) Details |
472cb69 to
9f281e0
Compare
|
EWS run on previous version of this PR (hash 9f281e0) Details |
9f281e0 to
d84f8db
Compare
|
EWS run on previous version of this PR (hash d84f8db) Details |
d84f8db to
cd84b8a
Compare
|
EWS run on previous version of this PR (hash cd84b8a) Details |
cd84b8a to
a126638
Compare
|
EWS run on previous version of this PR (hash a126638) Details |
a126638 to
bc286f6
Compare
|
EWS run on previous version of this PR (hash bc286f6) Details |
bc286f6 to
ecfd60c
Compare
|
EWS run on previous version of this PR (hash ecfd60c) Details |
ecfd60c to
3419d2d
Compare
|
EWS run on previous version of this PR (hash 3419d2d) Details |
https://bugs.webkit.org/show_bug.cgi?id=281289 Reviewed by NOBODY (OOPS!). This change adds parsing support for `position-area` CSS property as specified in: https://drafts.csswg.org/css-anchor-position-1/#position-area * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-computed-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-computed-insets-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-interpolation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-parsing-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/property-interpolations-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/try-tactic-position-area-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml-expected.txt: * LayoutTests/platform/glib/imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml-expected.txt: * LayoutTests/platform/ios/imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml-expected.txt: * LayoutTests/platform/ipad/imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml-expected.txt: * LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/css/css-cascade/all-prop-initial-xml-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/animation/CSSPropertyAnimation.cpp: (WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap): * Source/WebCore/css/CSSProperties.json: * Source/WebCore/css/CSSValueKeywords.in: * Source/WebCore/css/ComputedStyleExtractor.cpp: (WebCore::toCSSValueID): (WebCore::valueForPositionArea): (WebCore::ComputedStyleExtractor::valueForPropertyInStyle const): * Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp: (WebCore::CSSPropertyParserHelpers::consumePositionArea): * Source/WebCore/css/parser/CSSPropertyParserHelpers.h: * Source/WebCore/rendering/style/PositionArea.cpp: Added. (WebCore::PositionArea::isAmbiguous): (WebCore::operator<<): * Source/WebCore/rendering/style/PositionArea.h: Added. * Source/WebCore/rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::conservativelyCollectChangedAnimatableProperties const): * Source/WebCore/rendering/style/RenderStyle.h: * Source/WebCore/rendering/style/RenderStyleInlines.h: (WebCore::RenderStyle::initialPositionArea): (WebCore::RenderStyle::positionArea const): * Source/WebCore/rendering/style/RenderStyleSetters.h: (WebCore::RenderStyle::setPositionArea): * Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp: (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): (WebCore::StyleRareNonInheritedData::operator== const): * Source/WebCore/rendering/style/StyleRareNonInheritedData.h: * Source/WebCore/style/StyleBuilderConverter.h: (WebCore::Style::BuilderConverter::convertPositionArea):
3419d2d to
9f0532f
Compare
|
EWS run on current version of this PR (hash 9f0532f) Details |
tuankiet65
left a comment
There was a problem hiding this comment.
I haven't checked the parsing/serialization/conversion code closely, but the test passes so I'm confident they're correct
| enum CSSValueID : uint16_t; | ||
|
|
||
| struct PositionArea { | ||
|
|
| || id == CSSValueXStart | ||
| ); | ||
| }; | ||
| auto isDescribingRows = [&isDescribingCols](const CSSValueID id) { |
There was a problem hiding this comment.
Maybe add newlines between the lambda definitions
| }, | ||
| "position-area": { | ||
| "values": [ | ||
| "block-end", |
There was a problem hiding this comment.
If we are parsing the value ourselves, I don't know if this would do anything. I think it also gives the wrong impression that these are the values that position-area accepts, while the reality is more complicated.
There was a problem hiding this comment.
It mostly lists them on webkit.org/css-status , but nothing else really.
(Also none is missing from this list)
I'm fine either way regarding keeping this list.
| // https://drafts.csswg.org/css-anchor-position-1/#position-area | ||
| RefPtr<CSSValue> consumePositionArea(CSSParserTokenRange& range, const CSSParserContext&) | ||
| { | ||
| auto matchesBranch1A = [](const CSSValueID id) { |
There was a problem hiding this comment.
no need for const, here and below.
|
|
||
| inline std::optional<PositionArea> BuilderConverter::convertPositionArea(BuilderState&, const CSSValue& value) | ||
| { | ||
| auto isDescribingCols = [](const CSSValueID id) { |
| } | ||
| } | ||
|
|
||
| return std::nullopt; |
There was a problem hiding this comment.
We should never get here, right? So this should also be ASSERT_NOT_REACHED();
There was a problem hiding this comment.
A few comments...
First, it's not a good idea to name things after numerical indexes into the spec. The spec can get rearranged for editorial reasons, and it doesn't explain what the underlying logic is. The question you have to ask yourself is, why are are the branches oriented that way? I promise you there's good reasons. :) That logic is what you should use to organize your code.
Second, the grammar in the spec is written that way for understandability. It's not necessarily the best organization for implementing. In this case, if you consume the first ident, and it is not either center or span-all, then you can identify its axis as well as whether it should be first or second in canonical order. You can plug that into your output pair. With that information, you can know what kind of keyword is valid for the second axis, and validate and store it accordingly as well. If instead you fell through into the center or span-all case, then you store this value while you parse the second keyword, and then you can plug both into your output pair once you've identified the axis of the second keyword.
You can do this with switch/case, and it will not only be easier to understand, it'll also be faster than 50+ conditional branches (which is what || produces).
There was a problem hiding this comment.
This structure is about the computed value, not the specified value, right? So here you should think about how you intend to use the value, and encapsulate that logic accordingly. The users of this object don't care about the keywords. They are going to want to pass in some WritingMode information and get back out the used value in their own coordinate space. And they're going to want to get this information efficiently.
So think about abstracting the information in this class. What do the keywords really mean? Instead of maintaining a collection of keywords, you could, for example break this down into:
- Which of the start/center/end tracks are selected? (3 bits per axis)
- Am I interpreting the axis as a) physical coordinates b) container x/y logical coordinates c) self x/y logical coordinates d) container block/inline logical coordinates or e) self block/inline logical coordinates (3 bits per axis)
If you organize your values internally like this, then it'll be much easier to add on helper functions that rapidly return used values.
And also, if your parsing function is reliably returning the x or block value first, and the y or inline value second (which it should, because we should only be doing validation in one place, not two), then you can easily assign the parsed values into the computed value structure using switch/case.
|
@tuankiet65 @nt1m @fantasai thank you for comments! Those are my first steps implementing features in WebKit's CSS area so the comments from you all are very helpful. Right now I've switched my focus a bit to |
|
Due to the change of priorities I'm unable to work on it anymore. Therefore - as agreed offline - @tuankiet65 will continue the work on this feature. |
🛠 vision-sim
9f0532f
9f0532f