Commit 8d71cf34 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[scroll-animations] Make Scroll/DocumentTimeline decision earlier

Instead of storing a ScrollTimeline that may be nullptr, store an
AnimationTimeline that's already been determined to either be a
ScrollTimeline or a DocumentTimeline.

There should be no behavior change in this CL. It's a preparation that
will make subsequent work on dynamically updatable @scroll-timeline
rules a bit smoother.

It's also needed in the future to differentiate between animation-
timeline:auto and animation-timeline:none.

Note: Apparently inspector_css_cascade_test.cc previously depended on
some header transitively included via css_animation_update.h.

Bug: 1074052
Change-Id: Ic9704f3a08859244163fd911b65bef98bc0b2d74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332618Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795218}
parent c964c8f8
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_ANIMATION_UPDATE_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_ANIMATION_UPDATE_H_
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/renderer/core/animation/animation_timeline.h"
#include "third_party/blink/renderer/core/animation/effect_stack.h" #include "third_party/blink/renderer/core/animation/effect_stack.h"
#include "third_party/blink/renderer/core/animation/inert_effect.h" #include "third_party/blink/renderer/core/animation/inert_effect.h"
#include "third_party/blink/renderer/core/animation/interpolation.h" #include "third_party/blink/renderer/core/animation/interpolation.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect_model.h" #include "third_party/blink/renderer/core/animation/keyframe_effect_model.h"
#include "third_party/blink/renderer/core/animation/scroll_timeline.h"
#include "third_party/blink/renderer/core/css/css_keyframes_rule.h" #include "third_party/blink/renderer/core/css/css_keyframes_rule.h"
#include "third_party/blink/renderer/core/css/css_property_equality.h" #include "third_party/blink/renderer/core/css/css_property_equality.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
...@@ -33,7 +33,7 @@ class NewCSSAnimation { ...@@ -33,7 +33,7 @@ class NewCSSAnimation {
const InertEffect& effect, const InertEffect& effect,
Timing timing, Timing timing,
StyleRuleKeyframes* style_rule, StyleRuleKeyframes* style_rule,
ScrollTimeline* scroll_timeline, AnimationTimeline* timeline,
const Vector<EAnimPlayState>& play_state_list) const Vector<EAnimPlayState>& play_state_list)
: name(name), : name(name),
name_index(name_index), name_index(name_index),
...@@ -42,13 +42,13 @@ class NewCSSAnimation { ...@@ -42,13 +42,13 @@ class NewCSSAnimation {
timing(timing), timing(timing),
style_rule(style_rule), style_rule(style_rule),
style_rule_version(this->style_rule->Version()), style_rule_version(this->style_rule->Version()),
scroll_timeline(scroll_timeline), timeline(timeline),
play_state_list(play_state_list) {} play_state_list(play_state_list) {}
void Trace(Visitor* visitor) const { void Trace(Visitor* visitor) const {
visitor->Trace(effect); visitor->Trace(effect);
visitor->Trace(style_rule); visitor->Trace(style_rule);
visitor->Trace(scroll_timeline); visitor->Trace(timeline);
} }
AtomicString name; AtomicString name;
...@@ -58,7 +58,7 @@ class NewCSSAnimation { ...@@ -58,7 +58,7 @@ class NewCSSAnimation {
Timing timing; Timing timing;
Member<StyleRuleKeyframes> style_rule; Member<StyleRuleKeyframes> style_rule;
unsigned style_rule_version; unsigned style_rule_version;
Member<ScrollTimeline> scroll_timeline; Member<AnimationTimeline> timeline;
Vector<EAnimPlayState> play_state_list; Vector<EAnimPlayState> play_state_list;
}; };
...@@ -121,11 +121,11 @@ class CORE_EXPORT CSSAnimationUpdate final { ...@@ -121,11 +121,11 @@ class CORE_EXPORT CSSAnimationUpdate final {
const InertEffect& effect, const InertEffect& effect,
const Timing& timing, const Timing& timing,
StyleRuleKeyframes* style_rule, StyleRuleKeyframes* style_rule,
ScrollTimeline* scroll_timeline, AnimationTimeline* timeline,
const Vector<EAnimPlayState>& play_state_list) { const Vector<EAnimPlayState>& play_state_list) {
new_animations_.push_back( new_animations_.push_back(
NewCSSAnimation(animation_name, name_index, position_index, effect, NewCSSAnimation(animation_name, name_index, position_index, effect,
timing, style_rule, scroll_timeline, play_state_list)); timing, style_rule, timeline, play_state_list));
} }
void CancelAnimation(wtf_size_t index, const Animation& animation) { void CancelAnimation(wtf_size_t index, const Animation& animation) {
cancelled_animation_indices_.push_back(index); cancelled_animation_indices_.push_back(index);
......
...@@ -529,6 +529,15 @@ ScrollTimeline* CreateScrollTimeline(Element* element, ...@@ -529,6 +529,15 @@ ScrollTimeline* CreateScrollTimeline(Element* element,
return scroll_timeline; return scroll_timeline;
} }
AnimationTimeline* ComputeTimeline(Element* element,
StyleRuleScrollTimeline* rule) {
if (rule) {
if (auto* timeline = CreateScrollTimeline(element, rule))
return timeline;
}
return &element->GetDocument().Timeline();
}
} // namespace } // namespace
CSSAnimations::CSSAnimations() = default; CSSAnimations::CSSAnimations() = default;
...@@ -675,19 +684,18 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update, ...@@ -675,19 +684,18 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update,
const StyleNameOrKeyword& timeline_name = animation_data->GetTimeline(i); const StyleNameOrKeyword& timeline_name = animation_data->GetTimeline(i);
ScrollTimeline* scroll_timeline = nullptr; StyleRuleScrollTimeline* scroll_timeline_rule = nullptr;
// TODO(crbug.com/1097046): Support 'none' keyword. // TODO(crbug.com/1097046): Support 'none' keyword.
if (!timeline_name.IsKeyword()) { if (!timeline_name.IsKeyword()) {
StyleRuleScrollTimeline* scroll_timeline_rule = scroll_timeline_rule =
element.GetDocument().GetStyleEngine().FindScrollTimelineRule( element.GetDocument().GetStyleEngine().FindScrollTimelineRule(
timeline_name.GetName().GetValue()); timeline_name.GetName().GetValue());
if (scroll_timeline_rule) {
scroll_timeline =
CreateScrollTimeline(&element, scroll_timeline_rule);
}
} }
AnimationTimeline* timeline =
ComputeTimeline(&element, scroll_timeline_rule);
const RunningAnimation* existing_animation = nullptr; const RunningAnimation* existing_animation = nullptr;
wtf_size_t existing_animation_index = 0; wtf_size_t existing_animation_index = 0;
...@@ -751,9 +759,9 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update, ...@@ -751,9 +759,9 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update,
DCHECK(!is_animation_style_change); DCHECK(!is_animation_style_change);
base::Optional<TimelinePhase> inherited_phase; base::Optional<TimelinePhase> inherited_phase;
base::Optional<double> inherited_time = 0; base::Optional<double> inherited_time = 0;
if (scroll_timeline) { if (timeline && timeline->IsScrollTimeline()) {
inherited_phase = base::make_optional(scroll_timeline->Phase()); inherited_phase = base::make_optional(timeline->Phase());
inherited_time = scroll_timeline->CurrentTimeSeconds(); inherited_time = timeline->CurrentTimeSeconds();
} }
update.StartAnimation( update.StartAnimation(
name, name_index, i, name, name_index, i,
...@@ -762,7 +770,7 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update, ...@@ -762,7 +770,7 @@ void CSSAnimations::CalculateAnimationUpdate(CSSAnimationUpdate& update,
&style, parent_style, name, &style, parent_style, name,
keyframe_timing_function.get(), i), keyframe_timing_function.get(), i),
timing, is_paused, inherited_time, inherited_phase), timing, is_paused, inherited_time, inherited_phase),
specified_timing, keyframes_rule, scroll_timeline, specified_timing, keyframes_rule, timeline,
animation_data->PlayStateList()); animation_data->PlayStateList());
} }
} }
...@@ -903,9 +911,11 @@ void CSSAnimations::MaybeApplyPendingUpdate(Element* element) { ...@@ -903,9 +911,11 @@ void CSSAnimations::MaybeApplyPendingUpdate(Element* element) {
element, inert_animation->Model(), inert_animation->SpecifiedTiming(), element, inert_animation->Model(), inert_animation->SpecifiedTiming(),
KeyframeEffect::kDefaultPriority, event_delegate); KeyframeEffect::kDefaultPriority, event_delegate);
AnimationTimeline* timeline = &element->GetDocument().Timeline(); AnimationTimeline* timeline = entry.timeline;
if (entry.scroll_timeline) // We always fall back to the DocumentTimeline at the moment, so the
timeline = entry.scroll_timeline.Get(); // timeline can't be nullptr here.
// TODO(crbug.com/1097046): Support animation-timeline:none
DCHECK(timeline);
auto* animation = MakeGarbageCollected<CSSAnimation>( auto* animation = MakeGarbageCollected<CSSAnimation>(
element->GetExecutionContext(), timeline, effect, entry.position_index, element->GetExecutionContext(), timeline, effect, entry.position_index,
entry.name); entry.name);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_value.h" #include "third_party/blink/renderer/core/css/css_value.h"
#include "third_party/blink/renderer/core/css/css_value_list.h"
#include "third_party/blink/renderer/core/css/style_engine.h" #include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/html/html_element.h" #include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h" #include "third_party/blink/renderer/core/style/computed_style_constants.h"
......
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