Skip to content

Commit

Permalink
[scroll-animations] add parsing support for the scroll() notation o…
Browse files Browse the repository at this point in the history
…f the `animation-timeline` property

https://bugs.webkit.org/show_bug.cgi?id=265786

Reviewed by Antti Koivisto.

We now add parsing support for the `scroll()` notation of the `animation-timeline` property using a new
`CSSValue` subclass: `CSSScrollValue`. This will yield an anonymous `ScrollTimeline`.

* LayoutTests/imported/w3c/web-platform-tests/scroll-animations/css/animation-timeline-computed-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/scroll-animations/css/animation-timeline-parsing-expected.txt:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/animation/ScrollTimeline.cpp:
(WebCore::ScrollTimeline::createFromCSSValue):
(WebCore::ScrollTimeline::ScrollTimeline):
(WebCore::ScrollTimeline::toCSSValue const):
* Source/WebCore/animation/ScrollTimeline.h:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSScrollValue.cpp: Added.
(WebCore::CSSScrollValue::customCSSText const):
(WebCore::CSSScrollValue::equals const):
* Source/WebCore/css/CSSScrollValue.h: Added.
* Source/WebCore/css/CSSToStyleMap.cpp:
(WebCore::CSSToStyleMap::mapAnimationTimeline):
* Source/WebCore/css/CSSValue.cpp:
(WebCore::CSSValue::visitDerived):
* Source/WebCore/css/CSSValue.h:
(WebCore::CSSValue::isScrollValue const):
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/ComputedStyleExtractor.cpp:
(WebCore::valueForAnimationTimeline):
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeSingleAnimationTimeline):
(WebCore::CSSPropertyParserHelpers::consumeAnimationTimelineScroll):
* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
* Source/WebCore/platform/animation/Animation.cpp:
(WebCore::operator<<):
* Source/WebCore/platform/animation/Animation.h:
* Source/WebInspectorUI/UserInterface/Models/CSSKeywordCompletions.js:

Canonical link: https://commits.webkit.org/271477@main
  • Loading branch information
graouts committed Dec 4, 2023
1 parent 94ac298 commit 4eceb11
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ PASS Property animation-timeline value '--test1, --test2'
PASS Property animation-timeline value '--test1, --test2, none, --test3, auto'
PASS The animation-timeline property shows up in CSSStyleDeclaration enumeration
PASS The animation-timeline property shows up in CSSStyleDeclaration.cssText
FAIL Property animation-timeline value 'scroll()' assert_true: 'scroll()' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(block)' assert_true: 'scroll(block)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(inline)' assert_true: 'scroll(inline)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(x)' assert_true: 'scroll(x)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(y)' assert_true: 'scroll(y)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(root)' assert_true: 'scroll(root)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(nearest)' assert_true: 'scroll(nearest)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(self)' assert_true: 'scroll(self)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(self), scroll(nearest)' assert_true: 'scroll(self), scroll(nearest)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(inline nearest)' assert_true: 'scroll(inline nearest)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(nearest inline)' assert_true: 'scroll(nearest inline)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(block self)' assert_true: 'scroll(block self)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(self block)' assert_true: 'scroll(self block)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'scroll(y root)' assert_true: 'scroll(y root)' is a supported value for animation-timeline. expected true got false
PASS Property animation-timeline value 'scroll()'
PASS Property animation-timeline value 'scroll(block)'
PASS Property animation-timeline value 'scroll(inline)'
PASS Property animation-timeline value 'scroll(x)'
PASS Property animation-timeline value 'scroll(y)'
PASS Property animation-timeline value 'scroll(root)'
PASS Property animation-timeline value 'scroll(nearest)'
PASS Property animation-timeline value 'scroll(self)'
PASS Property animation-timeline value 'scroll(self), scroll(nearest)'
PASS Property animation-timeline value 'scroll(inline nearest)'
PASS Property animation-timeline value 'scroll(nearest inline)'
PASS Property animation-timeline value 'scroll(block self)'
PASS Property animation-timeline value 'scroll(self block)'
PASS Property animation-timeline value 'scroll(y root)'
FAIL Property animation-timeline value 'view()' assert_true: 'view()' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'view(block)' assert_true: 'view(block)' is a supported value for animation-timeline. expected true got false
FAIL Property animation-timeline value 'view(inline)' assert_true: 'view(inline)' is a supported value for animation-timeline. expected true got false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ PASS e.style['animation-timeline'] = "\"foo\" \"bar\"" should not set the proper
PASS e.style['animation-timeline'] = "rgb(1, 2, 3)" should not set the property value
PASS e.style['animation-timeline'] = "#fefefe" should not set the property value
PASS e.style['animation-timeline'] = "\"test\"" should not set the property value
FAIL e.style['animation-timeline'] = "scroll()" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = " scroll() " should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(block)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(inline)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(x)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(y)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(root)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(nearest)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(self)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(inline nearest)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(nearest inline)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(block self)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(self block)" should set the property value assert_not_equals: property should be set got disallowed value ""
FAIL e.style['animation-timeline'] = "scroll(y root)" should set the property value assert_not_equals: property should be set got disallowed value ""
PASS e.style['animation-timeline'] = "scroll()" should set the property value
PASS e.style['animation-timeline'] = " scroll() " should set the property value
PASS e.style['animation-timeline'] = "scroll(block)" should set the property value
PASS e.style['animation-timeline'] = "scroll(inline)" should set the property value
PASS e.style['animation-timeline'] = "scroll(x)" should set the property value
PASS e.style['animation-timeline'] = "scroll(y)" should set the property value
PASS e.style['animation-timeline'] = "scroll(root)" should set the property value
PASS e.style['animation-timeline'] = "scroll(nearest)" should set the property value
PASS e.style['animation-timeline'] = "scroll(self)" should set the property value
PASS e.style['animation-timeline'] = "scroll(inline nearest)" should set the property value
PASS e.style['animation-timeline'] = "scroll(nearest inline)" should set the property value
PASS e.style['animation-timeline'] = "scroll(block self)" should set the property value
PASS e.style['animation-timeline'] = "scroll(self block)" should set the property value
PASS e.style['animation-timeline'] = "scroll(y root)" should set the property value
PASS e.style['animation-timeline'] = "scroll(abc root)" should not set the property value
PASS e.style['animation-timeline'] = "scroll(abc)" should not set the property value
PASS e.style['animation-timeline'] = "scroll(y abc)" should not set the property value
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ css/CSSRegisteredCustomProperty.cpp
css/CSSRule.cpp
css/CSSRuleList.cpp
css/CSSScopeRule.cpp
css/CSSScrollValue.cpp
css/CSSSegmentedFontFace.cpp
css/CSSSelector.cpp
css/CSSSelectorList.cpp
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2672,6 +2672,7 @@
713171341FBE78DB00F758DE /* CSSPropertyBlendingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 713171321FBE78C500F758DE /* CSSPropertyBlendingClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
7132445120109DA500AE7FB2 /* WebAnimationUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7132444F20109D9B00AE7FB2 /* WebAnimationUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
7134496E146941B300720312 /* SVGLengthContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 7134496C146941B300720312 /* SVGLengthContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
7135168C2AE6C2BB00718EBE /* CSSScrollValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7135168A2AE6C27800718EBE /* CSSScrollValue.h */; };
713516932AE6D01F00718EBE /* ScrollTimeline.h in Headers */ = {isa = PBXBuildFile; fileRef = 713516912AE6D00A00718EBE /* ScrollTimeline.h */; settings = {ATTRIBUTES = (Private, ); }; };
713516982AE6D2AE00718EBE /* ScrollAxis.h in Headers */ = {isa = PBXBuildFile; fileRef = 713516962AE6D29600718EBE /* ScrollAxis.h */; settings = {ATTRIBUTES = (Private, ); }; };
713516992AE6D2B200718EBE /* ScrollTimelineOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 713516942AE6D29600718EBE /* ScrollTimelineOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -12642,6 +12643,8 @@
7132444F20109D9B00AE7FB2 /* WebAnimationUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAnimationUtilities.h; sourceTree = "<group>"; };
7134496B146941B300720312 /* SVGLengthContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGLengthContext.cpp; sourceTree = "<group>"; };
7134496C146941B300720312 /* SVGLengthContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGLengthContext.h; sourceTree = "<group>"; };
713516892AE6C27700718EBE /* CSSScrollValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSScrollValue.cpp; sourceTree = "<group>"; };
7135168A2AE6C27800718EBE /* CSSScrollValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSScrollValue.h; sourceTree = "<group>"; };
713516902AE6D00A00718EBE /* ScrollTimeline.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollTimeline.idl; sourceTree = "<group>"; };
713516912AE6D00A00718EBE /* ScrollTimeline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollTimeline.h; sourceTree = "<group>"; };
713516922AE6D00B00718EBE /* ScrollTimeline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollTimeline.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -35588,6 +35591,8 @@
BE0C0A9F2AFCE8A6004B7765 /* CSSScopeRule.cpp */,
BE0C0AA02AFCE8A7004B7765 /* CSSScopeRule.h */,
BE0C0AA12AFCE8A7004B7765 /* CSSScopeRule.idl */,
713516892AE6C27700718EBE /* CSSScrollValue.cpp */,
7135168A2AE6C27800718EBE /* CSSScrollValue.h */,
371F51A00D262FA000ECE0D5 /* CSSSegmentedFontFace.cpp */,
371F519F0D262FA000ECE0D5 /* CSSSegmentedFontFace.h */,
A80E73480A199C77007FB8C5 /* CSSSelector.cpp */,
Expand Down Expand Up @@ -38226,6 +38231,7 @@
A80E6D0D0A1989CA007FB8C5 /* CSSRule.h in Headers */,
A80E6CF20A1989CA007FB8C5 /* CSSRuleList.h in Headers */,
2A538A2926F0103F00965FC8 /* CSSScale.h in Headers */,
7135168C2AE6C2BB00718EBE /* CSSScrollValue.h in Headers */,
371F51A10D262FA000ECE0D5 /* CSSSegmentedFontFace.h in Headers */,
A80E73520A199C77007FB8C5 /* CSSSelector.h in Headers */,
E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */,
Expand Down
53 changes: 53 additions & 0 deletions Source/WebCore/animation/ScrollTimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "config.h"
#include "ScrollTimeline.h"

#include "CSSPrimitiveValueMappings.h"
#include "CSSScrollValue.h"
#include "Element.h"

namespace WebCore {
Expand All @@ -40,6 +42,32 @@ Ref<ScrollTimeline> ScrollTimeline::create(const AtomString& name, ScrollAxis ax
return adoptRef(*new ScrollTimeline(name, axis));
}

Ref<ScrollTimeline> ScrollTimeline::createFromCSSValue(const CSSScrollValue& cssScrollValue)
{
auto scroller = [&]() {
auto scrollerValue = cssScrollValue.scroller();
if (!scrollerValue)
return Scroller::Nearest;

switch (scrollerValue->valueID()) {
case CSSValueNearest:
return Scroller::Nearest;
case CSSValueRoot:
return Scroller::Root;
case CSSValueSelf:
return Scroller::Self;
default:
ASSERT_NOT_REACHED();
return Scroller::Nearest;
}
}();

auto axisValue = cssScrollValue.axis();
auto axis = axisValue ? fromCSSValueID<ScrollAxis>(axisValue->valueID()) : ScrollAxis::Block;

return adoptRef(*new ScrollTimeline(scroller, axis));
}

ScrollTimeline::ScrollTimeline(ScrollTimelineOptions&& options)
: m_source(WTFMove(options.source))
, m_axis(options.axis)
Expand All @@ -52,4 +80,29 @@ ScrollTimeline::ScrollTimeline(const AtomString& name, ScrollAxis axis)
{
}

ScrollTimeline::ScrollTimeline(Scroller scroller, ScrollAxis axis)
: m_axis(axis)
, m_scroller(scroller)
{
}

Ref<CSSValue> ScrollTimeline::toCSSValue() const
{
auto scroller = [&]() {
switch (m_scroller) {
case Scroller::Nearest:
return CSSValueNearest;
case Scroller::Root:
return CSSValueRoot;
case Scroller::Self:
return CSSValueSelf;
default:
ASSERT_NOT_REACHED();
return CSSValueNearest;
}
}();

return CSSScrollValue::create(CSSPrimitiveValue::create(scroller), CSSPrimitiveValue::create(toCSSValueID(m_axis)));
}

} // namespace WebCore
8 changes: 8 additions & 0 deletions Source/WebCore/animation/ScrollTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@

namespace WebCore {

class CSSScrollValue;
class Element;

class ScrollTimeline : public AnimationTimeline {
public:
static Ref<ScrollTimeline> create(ScrollTimelineOptions&& = { });
static Ref<ScrollTimeline> create(const AtomString&, ScrollAxis);
static Ref<ScrollTimeline> createFromCSSValue(const CSSScrollValue&);

Element* source() const { return m_source.get(); }

Expand All @@ -48,17 +50,23 @@ class ScrollTimeline : public AnimationTimeline {
const AtomString& name() const { return m_name; }
void setName(const AtomString& name) { m_name = name; }

Ref<CSSValue> toCSSValue() const;

protected:
explicit ScrollTimeline(const AtomString&, ScrollAxis);

private:
enum class Scroller : uint8_t { Nearest, Root, Self };

explicit ScrollTimeline(ScrollTimelineOptions&& = { });
explicit ScrollTimeline(Scroller, ScrollAxis);

bool isScrollTimeline() const final { return true; }

WeakPtr<Element, WeakPtrImplWithEventTargetData> m_source;
ScrollAxis m_axis { ScrollAxis::Block };
AtomString m_name;
Scroller m_scroller { Scroller::Nearest };
};

} // namespace WebCore
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/css/CSSProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -11096,6 +11096,14 @@
"url": "https://drafts.csswg.org/scroll-animations-1/#scroll-notation"
}
},
"<scroller>": {
"grammar": "root | nearest | self",
"exported": true,
"specification": {
"category": "scroll-animations",
"url": "https://drafts.csswg.org/scroll-animations-1/#scroll-notation"
}
},
"<single-scroll-timeline-name>": {
"grammar": "none | <dashed-ident>",
"exported": true,
Expand Down
56 changes: 56 additions & 0 deletions Source/WebCore/css/CSSScrollValue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "CSSScrollValue.h"

#include "CSSPrimitiveValueMappings.h"

namespace WebCore {

String CSSScrollValue::customCSSText() const
{
auto hasScroller = m_scroller && m_scroller->valueID() != CSSValueNearest;
auto hasAxis = m_axis && m_axis->valueID() != CSSValueBlock;

return makeString(
"scroll("_s,
hasScroller ? m_scroller->cssText() : ""_s,
hasScroller && hasAxis ? " "_s : ""_s,
hasAxis ? m_axis->cssText() : ""_s,
")"_s
);
}

bool CSSScrollValue::equals(const CSSScrollValue& other) const
{
return compareCSSValuePtr(m_scroller, other.m_scroller)
&& compareCSSValuePtr(m_axis, other.m_axis);
}

}
Loading

0 comments on commit 4eceb11

Please sign in to comment.