Skip to content

Commit

Permalink
[scroll-animations] Make view-timeline-name tree-scoped
Browse files Browse the repository at this point in the history
This CL stores a list of ScopedCSSNames instead of a Vector of
AtomicStrings.

Even though it's not possible for the names of a single CSS property
to be associated with different TreeScopes, we store the TreeScope
pointer in full for every name. This is to prepare for additive
cascading, where such a situation would be possible.

There should be no behavior change. Actually making use the TreeScope
information will happen in a future CL.

Bug: 1382876
Change-Id: I04da820f2aad871e54fe146603e06d5d0a17e9af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4055473
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1076152}
  • Loading branch information
andruud authored and Chromium LUCI CQ committed Nov 28, 2022
1 parent f0e8aae commit 5589fdd
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 29 deletions.
22 changes: 15 additions & 7 deletions third_party/blink/renderer/core/animation/css/css_animations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,13 @@ void CSSAnimations::CalculateViewTimelineUpdate(
CSSAnimationUpdate& update,
Element& animating_element,
const ComputedStyleBuilder& style_builder) {
const Vector<AtomicString>& names = style_builder.ViewTimelineName();
const Vector<TimelineAxis>& axes = style_builder.ViewTimelineAxis();
const Vector<TimelineInset>& insets = style_builder.ViewTimelineInset();

const CSSAnimations::TimelineData* timeline_data =
GetTimelineData(animating_element);

if (names.empty() && (!timeline_data || timeline_data->IsEmpty()))
if (!style_builder.ViewTimelineName() &&
(!timeline_data || timeline_data->IsEmpty())) {
return;
}

CSSViewTimelineMap changed_timelines;

Expand All @@ -521,10 +519,20 @@ void CSSAnimations::CalculateViewTimelineUpdate(
}
}

const HeapVector<Member<const ScopedCSSName>>& names =
style_builder.ViewTimelineName()
? style_builder.ViewTimelineName()->GetNames()
: HeapVector<Member<const ScopedCSSName>>();
const Vector<TimelineAxis>& axes = style_builder.ViewTimelineAxis();
const Vector<TimelineInset>& insets = style_builder.ViewTimelineInset();

for (wtf_size_t i = 0; i < names.size(); ++i) {
const AtomicString& name = names[i];
if (name.empty())
if (!names[i]) {
// A value of nullptr means "none".
continue;
}
// TODO(crbug.com/1382876): Handle TreeScopes.
const AtomicString& name = names[i]->GetName();
TimelineAxis axis = axes.empty() ? TimelineAxis::kBlock
: axes[std::min(i, axes.size() - 1)];
const TimelineInset& inset = insets.empty()
Expand Down
6 changes: 4 additions & 2 deletions third_party/blink/renderer/core/css/css_properties.json5
Original file line number Diff line number Diff line change
Expand Up @@ -5088,8 +5088,10 @@
property_methods: ["ParseSingleValue", "CSSValueFromComputedStyleInternal", "InitialValue"],
field_group: "*->timeline",
field_template: "external",
default_value: "Vector<AtomicString>()",
type_name: "Vector<AtomicString>",
default_value: "nullptr",
type_name: "ScopedCSSNameList",
wrapper_pointer_name: "Persistent",
tree_scoped_value: true,
converter: "ConvertViewTimelineName",
separator: ",",
runtime_flag: "CSSViewTimeline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ CSSValue* ComputedStyleUtils::ValueForAnimationTimelineList(
}

CSSValue* ComputedStyleUtils::SingleValueForViewTimelineShorthand(
const AtomicString& name,
const ScopedCSSName* name,
TimelineAxis axis) {
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
list->Append(*ValueForCustomIdentOrNone(name));
Expand Down Expand Up @@ -3293,6 +3293,11 @@ CSSValue* ComputedStyleUtils::ValueForCustomIdentOrNone(
return MakeGarbageCollected<CSSCustomIdentValue>(ident);
}

CSSValue* ComputedStyleUtils::ValueForCustomIdentOrNone(
const ScopedCSSName* name) {
return ValueForCustomIdentOrNone(name ? name->GetName() : g_null_atom);
}

const CSSValue* ComputedStyleUtils::ValueForStyleAutoColor(
const ComputedStyle& style,
const StyleAutoColor& color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ class CORE_EXPORT ComputedStyleUtils {
static CSSValue* ValueForAnimationTimingFunctionList(const CSSTimingData*);
static CSSValue* ValueForAnimationTimelineList(const CSSAnimationData*);

static CSSValue* SingleValueForViewTimelineShorthand(const AtomicString& name,
TimelineAxis);
static CSSValue* SingleValueForViewTimelineShorthand(
const ScopedCSSName* name,
TimelineAxis);
static CSSValueList* ValuesForBorderRadiusCorner(const LengthSize&,
const ComputedStyle&);
static CSSValue* ValueForBorderRadiusCorner(const LengthSize&,
Expand Down Expand Up @@ -287,6 +288,7 @@ class CORE_EXPORT ComputedStyleUtils {
static CSSValue* ValueForStyleName(const StyleName&);
static CSSValue* ValueForStyleNameOrKeyword(const StyleNameOrKeyword&);
static CSSValue* ValueForCustomIdentOrNone(const AtomicString&);
static CSSValue* ValueForCustomIdentOrNone(const ScopedCSSName*);
static const CSSValue* ValueForStyleAutoColor(const ComputedStyle&,
const StyleAutoColor&,
CSSValuePhase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7923,12 +7923,12 @@ const CSSValue* ViewTimelineName::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const LayoutObject* layout_object,
bool allow_visited_style) const {
const Vector<AtomicString>& vector = style.ViewTimelineName();
if (vector.empty())
if (!style.ViewTimelineName())
return InitialValue();
CSSValueList* list = CSSValueList::CreateCommaSeparated();
for (const AtomicString& name : vector) {
list->Append(*ComputedStyleUtils::ValueForCustomIdentOrNone(name));
for (const Member<const ScopedCSSName>& name :
style.ViewTimelineName()->GetNames()) {
list->Append(*ComputedStyleUtils::ValueForCustomIdentOrNone(name.Get()));
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3000,15 +3000,17 @@ const CSSValue* ViewTimeline::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const LayoutObject*,
bool allow_visited_style) const {
const Vector<AtomicString>& name_vector = style.ViewTimelineName();
const HeapVector<Member<const ScopedCSSName>>& name_vector =
style.ViewTimelineName() ? style.ViewTimelineName()->GetNames()
: HeapVector<Member<const ScopedCSSName>>{};
const Vector<TimelineAxis>& axis_vector = style.ViewTimelineAxis();

CSSValueList* list = CSSValueList::CreateCommaSeparated();

if (name_vector.size() == axis_vector.size()) {
for (wtf_size_t i = 0; i < name_vector.size(); ++i) {
list->Append(*ComputedStyleUtils::SingleValueForViewTimelineShorthand(
name_vector[i], axis_vector[i]));
name_vector[i].Get(), axis_vector[i]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2854,14 +2854,16 @@ Vector<TimelineInset> StyleBuilderConverter::ConvertViewTimelineInset(
return insets;
}

Vector<AtomicString> StyleBuilderConverter::ConvertViewTimelineName(
ScopedCSSNameList* StyleBuilderConverter::ConvertViewTimelineName(
StyleResolverState& state,
const CSSValue& value) {
Vector<AtomicString> names;
for (const Member<const CSSValue>& item : To<CSSValueList>(value)) {
names.push_back(ConvertNoneOrCustomIdent(state, *item));
const ScopedCSSValue& value) {
HeapVector<Member<const ScopedCSSName>> names;
for (const Member<const CSSValue>& item :
To<CSSValueList>(value.GetCSSValue())) {
names.push_back(ConvertNoneOrCustomIdent(
state, ScopedCSSValue(*item, value.GetTreeScope())));
}
return names;
return MakeGarbageCollected<ScopedCSSNameList>(std::move(names));
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ class StyleBuilderConverter {
const CSSValue&);
static Vector<TimelineInset> ConvertViewTimelineInset(StyleResolverState&,
const CSSValue&);
static Vector<AtomicString> ConvertViewTimelineName(StyleResolverState&,
const CSSValue&);
static ScopedCSSNameList* ConvertViewTimelineName(StyleResolverState&,
const ScopedCSSValue&);
};

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool HasAnimationsOrTransitions(const StyleResolverState& state) {
bool HasTimelines(const StyleResolverState& state) {
if (!state.StyleBuilder().ScrollTimelineName().empty())
return true;
if (!state.StyleBuilder().ViewTimelineName().empty())
if (state.StyleBuilder().ViewTimelineName())
return true;
if (ElementAnimations* element_animations = GetElementAnimations(state))
return element_animations->CssAnimations().HasTimelines();
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/style/computed_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ static bool DiffAffectsScrollAnimations(const ComputedStyle& old_style,
static bool AffectsScrollAnimations(const ComputedStyle* old_style,
const ComputedStyle* new_style) {
if (old_style && !(old_style->ScrollTimelineName().empty() &&
old_style->ViewTimelineName().empty())) {
!old_style->ViewTimelineName())) {
return true;
}
if (new_style && !(new_style->ScrollTimelineName().empty() &&
new_style->ViewTimelineName().empty())) {
!new_style->ViewTimelineName())) {
return true;
}
return false;
Expand Down
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/style/scoped_css_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ void ScopedCSSName::Trace(Visitor* visitor) const {
visitor->Trace(tree_scope_);
}

void ScopedCSSNameList::Trace(Visitor* visitor) const {
visitor->Trace(names_);
}

} // namespace blink
34 changes: 34 additions & 0 deletions third_party/blink/renderer/core/style/scoped_css_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_SCOPED_CSS_NAME_H_

#include "base/memory/values_equivalent.h"
#include "base/ranges/algorithm.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
Expand Down Expand Up @@ -55,6 +57,38 @@ class CORE_EXPORT ScopedCSSName : public GarbageCollected<ScopedCSSName> {
WeakMember<const TreeScope> tree_scope_;
};

// Represents a list of tree-scoped names (or tree-scoped references).
//
// https://drafts.csswg.org/css-scoping/#css-tree-scoped-name
// https://drafts.csswg.org/css-scoping/#css-tree-scoped-reference
class CORE_EXPORT ScopedCSSNameList
: public GarbageCollected<ScopedCSSNameList> {
public:
explicit ScopedCSSNameList(HeapVector<Member<const ScopedCSSName>> names)
: names_(std::move(names)) {
DCHECK(!names_.empty());
}

const HeapVector<Member<const ScopedCSSName>>& GetNames() const {
return names_;
}

bool operator==(const ScopedCSSNameList& other) const {
return base::ranges::equal(names_, other.names_,
[](const auto& a, const auto& b) {
return base::ValuesEquivalent(a, b);
});
}
bool operator!=(const ScopedCSSNameList& other) const {
return !operator==(other);
}

void Trace(Visitor* visitor) const;

private:
HeapVector<Member<const ScopedCSSName>> names_;
};

} // namespace blink

namespace WTF {
Expand Down

0 comments on commit 5589fdd

Please sign in to comment.