Skip to content

Commit

Permalink
[scroll-animations] Make animation-timeline tree-scoped
Browse files Browse the repository at this point in the history
This is in preparation of tree-scoped timeline lookups.

There is no behavior change.

Bug: 1382876
Change-Id: Id4a884136c94443fa26dcb6f773527b0d941e3b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4061471
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1076759}
  • Loading branch information
andruud authored and Chromium LUCI CQ committed Nov 29, 2022
1 parent 584af67 commit e383762
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ state.GetFontBuilder().{{property.setter}}
{%- endif %}
{% endmacro %}

{% macro add_tree_scope(property, value, tree_scope) %}
{%- if property.tree_scoped_value %}
ScopedCSSValue({{value}}, {{tree_scope}})
{%- else %}
{{value}}
{%- endif %}
{% endmacro %}

{% macro remove_tree_scope(property, value) %}
{%- if property.tree_scoped_value %}
{{value}}.GetCSSValue()
{%- else %}
{{value}}
{%- endif %}
{% endmacro %}

{% macro style_builder_functions(property) %}
{% if not property.style_builder_template %}
{% call(property) apply_initial(property) %}
Expand Down Expand Up @@ -225,8 +241,10 @@ state.GetFontBuilder().{{property.setter}}
{% call(property) apply_value(property) %}
CSS{{animation}}Data& data = state.StyleBuilder().Access{{animation}}s();
data.{{vector}}.clear();
for (auto& listValue : To<CSSValueList>(value))
data.{{vector}}.push_back(CSSToStyleMap::MapAnimation{{attribute}}(*listValue));
for (const CSSValue* list_value : To<CSSValueList>({{remove_tree_scope(property, 'value')}})) {
const auto& item = {{add_tree_scope(property, '*list_value', 'value.GetTreeScope()')}};
data.{{vector}}.push_back(CSSToStyleMap::MapAnimation{{attribute}}(item));
}
{% endcall %}
{% elif property.style_builder_template in ['background_layer', 'mask_layer'] %}
{% set layer_type = 'Background' if property.style_builder_template == 'background_layer' else 'Mask' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,10 @@ AnimationTimeline* CSSAnimations::ComputeTimeline(
return nullptr;
}
if (style_timeline.IsName()) {
return FindPreviousSiblingAncestorTimeline(style_timeline.GetName(),
element, &update);
const ScopedCSSName& scoped_name = style_timeline.GetName();
// TODO(crbug.com/1382876): Handle TreeScope.
return FindPreviousSiblingAncestorTimeline(scoped_name.GetName(), element,
&update);
}
DCHECK(style_timeline.IsScroll());
return ComputeScrollFunctionTimeline(element, style_timeline.GetScroll());
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/css/css_properties.json5
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@
},
keywords: ["none", "auto"],
typedom_types: ["Keyword"],
tree_scoped_value: true,
separator: ",",
valid_for_marker: true,
runtime_flag: "CSSScrollTimeline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,8 @@ CSSValue* ComputedStyleUtils::ValueForAnimationTimeline(
return CSSIdentifierValue::Create(timeline.GetKeyword());
}
if (timeline.IsName()) {
const AtomicString& name = timeline.GetName();
const ScopedCSSName& scoped_name = timeline.GetName();
const AtomicString& name = scoped_name.GetName();
// Serialize as <string> if the value is not a valid <custom-ident>.
if (css_parsing_utils::IsCSSWideKeyword(name) ||
EqualIgnoringASCIICase(name, "auto") ||
Expand Down
11 changes: 8 additions & 3 deletions third_party/blink/renderer/core/css/resolver/css_to_style_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "third_party/blink/renderer/core/css/css_value_pair.h"
#include "third_party/blink/renderer/core/css/resolver/style_builder_converter.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
#include "third_party/blink/renderer/core/css/scoped_css_value.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/style/border_image_length_box.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
Expand Down Expand Up @@ -386,7 +387,9 @@ AtomicString CSSToStyleMap::MapAnimationName(const CSSValue& value) {
return CSSAnimationData::InitialName();
}

StyleTimeline CSSToStyleMap::MapAnimationTimeline(const CSSValue& value) {
StyleTimeline CSSToStyleMap::MapAnimationTimeline(
const ScopedCSSValue& scoped_value) {
const CSSValue& value = scoped_value.GetCSSValue();
if (value.IsInitialValue())
return CSSAnimationData::InitialTimeline();
if (auto* ident = DynamicTo<CSSIdentifierValue>(value)) {
Expand All @@ -395,10 +398,12 @@ StyleTimeline CSSToStyleMap::MapAnimationTimeline(const CSSValue& value) {
return StyleTimeline(ident->GetValueID());
}
if (auto* custom_ident = DynamicTo<CSSCustomIdentValue>(value)) {
return StyleTimeline(custom_ident->Value());
return StyleTimeline(MakeGarbageCollected<ScopedCSSName>(
custom_ident->Value(), scoped_value.GetTreeScope()));
}
if (auto* string_value = DynamicTo<CSSStringValue>(value)) {
return StyleTimeline(AtomicString(string_value->Value()));
return StyleTimeline(MakeGarbageCollected<ScopedCSSName>(
AtomicString(string_value->Value()), scoped_value.GetTreeScope()));
}
const auto& scroll_value = To<cssvalue::CSSScrollValue>(value);
const auto* axis_value = DynamicTo<CSSIdentifierValue>(scroll_value.Axis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CSSValue;
class StyleResolverState;
class NinePieceImage;
class BorderImageLengthBox;
class ScopedCSSValue;

class CSSToStyleMap {
STATIC_ONLY(CSSToStyleMap);
Expand Down Expand Up @@ -74,7 +75,7 @@ class CSSToStyleMap {
static Timing::FillMode MapAnimationFillMode(const CSSValue&);
static double MapAnimationIterationCount(const CSSValue&);
static AtomicString MapAnimationName(const CSSValue&);
static StyleTimeline MapAnimationTimeline(const CSSValue&);
static StyleTimeline MapAnimationTimeline(const ScopedCSSValue&);
static EAnimPlayState MapAnimationPlayState(const CSSValue&);
static CSSTransitionData::TransitionProperty MapAnimationProperty(
const CSSValue&);
Expand Down
18 changes: 14 additions & 4 deletions third_party/blink/renderer/core/style/style_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_TIMELINE_H_

#include "base/check_op.h"
#include "base/memory/values_equivalent.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/scoped_css_name.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"

namespace blink {
Expand Down Expand Up @@ -46,26 +49,33 @@ class CORE_EXPORT StyleTimeline {
};

explicit StyleTimeline(CSSValueID keyword) : data_(keyword) {}
explicit StyleTimeline(const AtomicString& name) : data_(name) {}
explicit StyleTimeline(const ScopedCSSName* name) : data_(name) {}
explicit StyleTimeline(const ScrollData& scroll_data) : data_(scroll_data) {}

bool operator==(const StyleTimeline& other) const {
if (IsName() && other.IsName()) {
return base::ValuesEquivalent(&GetName(), &other.GetName());
}
return data_ == other.data_;
}
bool operator!=(const StyleTimeline& other) const {
return !(*this == other);
}

bool IsKeyword() const { return absl::holds_alternative<CSSValueID>(data_); }
bool IsName() const { return absl::holds_alternative<AtomicString>(data_); }
bool IsName() const {
return absl::holds_alternative<Persistent<const ScopedCSSName>>(data_);
}
bool IsScroll() const { return absl::holds_alternative<ScrollData>(data_); }

const CSSValueID& GetKeyword() const { return absl::get<CSSValueID>(data_); }
const AtomicString& GetName() const { return absl::get<AtomicString>(data_); }
const ScopedCSSName& GetName() const {
return *absl::get<Persistent<const ScopedCSSName>>(data_);
}
const ScrollData& GetScroll() const { return absl::get<ScrollData>(data_); }

private:
absl::variant<CSSValueID, AtomicString, ScrollData> data_;
absl::variant<CSSValueID, Persistent<const ScopedCSSName>, ScrollData> data_;
};

} // namespace blink
Expand Down

0 comments on commit e383762

Please sign in to comment.