Commit 3685bab6 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[scroll-animations] Introduce CSSScrollTimelineOptions

Previously, a StyleRuleScrollTimeline would produce a ScrollTimeline
directly. This CL introduces CSSScrollTimelineOptions as an
intermediate  between the two. On its own, this is not terribly
useful, but it will become useful in the future when we implement
support for dynamically changing @scroll-timeline rules. We'd create
*two* CSSScrollTimelineOptions instances: one from the
updated @scroll-timeline rule, and one from the current ScrollTimeline
of the running animation. Given those two CSSScrollTimelineOptions
instances, we can then compare them for equality, and either do
nothing if they are equal, or create and set a new ScrollTimeline
if they are not.

Bug: 1074052
Change-Id: Ic3c26beda1dc297a4f8e6c168fa3750f8a0c040b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332599
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795422}
parent 3a0ee0e3
......@@ -493,6 +493,16 @@ ScrollTimelineOffset* ComputeScrollOffset(const CSSValue* value) {
return MakeGarbageCollected<ScrollTimelineOffset>();
}
HeapVector<Member<ScrollTimelineOffset>>* ComputeScrollOffsets(
const CSSValue* start,
const CSSValue* end) {
auto* offsets =
MakeGarbageCollected<HeapVector<Member<ScrollTimelineOffset>>>();
offsets->push_back(ComputeScrollOffset(start));
offsets->push_back(ComputeScrollOffset(end));
return offsets;
}
base::Optional<double> ComputeTimeRange(const CSSValue* value) {
if (auto* primitive = DynamicTo<CSSPrimitiveValue>(value))
return primitive->ComputeSeconds() * 1000.0;
......@@ -500,26 +510,32 @@ base::Optional<double> ComputeTimeRange(const CSSValue* value) {
return base::nullopt;
}
struct CSSScrollTimelineOptions {
STACK_ALLOCATED();
public:
CSSScrollTimelineOptions(Element* element, StyleRuleScrollTimeline& rule)
: source(ComputeScrollSource(element, rule.GetSource())),
direction(ComputeScrollDirection(rule.GetOrientation())),
offsets(ComputeScrollOffsets(rule.GetStart(), rule.GetEnd())),
time_range(ComputeTimeRange(rule.GetTimeRange())) {}
Element* source;
ScrollTimeline::ScrollDirection direction;
HeapVector<Member<ScrollTimelineOffset>>* offsets;
base::Optional<double> time_range;
};
ScrollTimeline* CreateScrollTimeline(Element* element,
StyleRuleScrollTimeline* rule) {
if (!rule)
return nullptr;
base::Optional<double> scroll_time_range =
ComputeTimeRange(rule->GetTimeRange());
if (!scroll_time_range)
CSSScrollTimelineOptions options(element, *rule);
if (!options.time_range)
return nullptr;
Element* source = ComputeScrollSource(element, rule->GetSource());
ScrollTimeline::ScrollDirection direction =
ComputeScrollDirection(rule->GetOrientation());
ScrollTimelineOffset* start = ComputeScrollOffset(rule->GetStart());
ScrollTimelineOffset* end = ComputeScrollOffset(rule->GetEnd());
HeapVector<Member<ScrollTimelineOffset>>* scroll_offsets =
MakeGarbageCollected<HeapVector<Member<ScrollTimelineOffset>>>();
scroll_offsets->push_back(start);
scroll_offsets->push_back(end);
auto* scroll_timeline = MakeGarbageCollected<ScrollTimeline>(
&element->GetDocument(), source, direction, scroll_offsets,
*scroll_time_range);
&element->GetDocument(), options.source, options.direction,
options.offsets, *options.time_range);
// It's is not allowed for a style resolve to create timelines that
// needs timing updates (i.e. AnimationTimeline::NeedsAnimationTimingUpdate()
// must return false). Servicing animations after creation preserves this
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment