LibWeb: Remove "resolved" from the name of Keyframe's property map

These will need to store unresolved styles as well, since they may be
built during parsing of a @keyframes rule. In that case there is no
target element or pseudo-element, and thus the value cannot be resolved.
This commit is contained in:
Matthew Olsson 2024-03-17 17:22:12 -07:00 committed by Andreas Kling
parent c92f556aa5
commit ebfc6c33a6
Notes: sideshowbarker 2024-07-16 16:23:32 +09:00
3 changed files with 13 additions and 11 deletions

View File

@ -551,8 +551,8 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr<KeyFrameSet> keyfr
// 0% or one that would be positioned earlier in the used keyframe order, add the computed value of that
// property on element to initial keyframes keyframe values.
for (auto property : animated_properties) {
if (!initial_keyframe->resolved_properties.contains(property))
initial_keyframe->resolved_properties.set(property, KeyFrameSet::UseInitial {});
if (!initial_keyframe->properties.contains(property))
initial_keyframe->properties.set(property, KeyFrameSet::UseInitial {});
}
// 3. If initial keyframes keyframe values is not empty, prepend initial keyframe to keyframes.
@ -568,8 +568,8 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr<KeyFrameSet> keyfr
}
for (auto property : animated_properties) {
if (!final_keyframe->resolved_properties.contains(property))
final_keyframe->resolved_properties.set(property, KeyFrameSet::UseInitial {});
if (!final_keyframe->properties.contains(property))
final_keyframe->properties.set(property, KeyFrameSet::UseInitial {});
}
}
@ -839,7 +839,7 @@ WebIDL::ExceptionOr<void> KeyframeEffect::set_keyframes(Optional<JS::Handle<JS::
for (auto const& [property_id, property_value] : keyframe.parsed_properties()) {
CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, [&](CSS::PropertyID shorthand_id, CSS::StyleValue const& shorthand_value) {
m_target_properties.set(shorthand_id);
resolved_keyframe.resolved_properties.set(shorthand_id, NonnullRefPtr<CSS::StyleValue const> { shorthand_value });
resolved_keyframe.properties.set(shorthand_id, NonnullRefPtr<CSS::StyleValue const> { shorthand_value });
});
}

View File

@ -64,7 +64,9 @@ public:
struct KeyFrameSet : public RefCounted<KeyFrameSet> {
struct UseInitial { };
struct ResolvedKeyFrame {
HashMap<CSS::PropertyID, Variant<UseInitial, NonnullRefPtr<CSS::StyleValue const>>> resolved_properties {};
// These StyleValue properties can be unresolved, as they may be generated from a @keyframes rule, well
// before they are applied to an element
HashMap<CSS::PropertyID, Variant<UseInitial, NonnullRefPtr<CSS::StyleValue const>>> properties {};
};
RedBlackTree<u64, ResolvedKeyFrame> keyframes_by_key;
};

View File

@ -1337,11 +1337,11 @@ void StyleComputer::collect_animation_into(JS::NonnullGCPtr<Animations::Keyframe
}();
if constexpr (LIBWEB_CSS_ANIMATION_DEBUG) {
auto valid_properties = keyframe_values.resolved_properties.size();
auto valid_properties = keyframe_values.properties.size();
dbgln("Animation {} contains {} properties to interpolate, progress = {}%", animation->id(), valid_properties, progress_in_keyframe * 100);
}
for (auto const& it : keyframe_values.resolved_properties) {
for (auto const& it : keyframe_values.properties) {
auto resolve_property = [&](auto& property) {
return property.visit(
[&](Animations::KeyframeEffect::KeyFrameSet::UseInitial) -> RefPtr<StyleValue const> {
@ -1354,7 +1354,7 @@ void StyleComputer::collect_animation_into(JS::NonnullGCPtr<Animations::Keyframe
auto resolved_start_property = resolve_property(it.value);
auto const& end_property = keyframe_end_values.resolved_properties.get(it.key);
auto const& end_property = keyframe_end_values.properties.get(it.key);
if (!end_property.has_value()) {
if (resolved_start_property) {
style_properties.set_animated_property(it.key, *resolved_start_property);
@ -2423,7 +2423,7 @@ NonnullOwnPtr<StyleComputer::RuleCache> StyleComputer::make_rule_cache_for_casca
for (auto const& it : keyframe_style.properties()) {
for_each_property_expanding_shorthands(it.property_id, it.value, [&](PropertyID shorthand_id, StyleValue const& shorthand_value) {
animated_properties.set(shorthand_id);
resolved_keyframe.resolved_properties.set(shorthand_id, NonnullRefPtr<StyleValue const> { shorthand_value });
resolved_keyframe.properties.set(shorthand_id, NonnullRefPtr<StyleValue const> { shorthand_value });
});
}
@ -2435,7 +2435,7 @@ NonnullOwnPtr<StyleComputer::RuleCache> StyleComputer::make_rule_cache_for_casca
if constexpr (LIBWEB_CSS_DEBUG) {
dbgln("Resolved keyframe set '{}' into {} keyframes:", rule.name(), keyframe_set->keyframes_by_key.size());
for (auto it = keyframe_set->keyframes_by_key.begin(); it != keyframe_set->keyframes_by_key.end(); ++it)
dbgln(" - keyframe {}: {} properties", it.key(), it->resolved_properties.size());
dbgln(" - keyframe {}: {} properties", it.key(), it->properties.size());
}
rule_cache->rules_by_animation_keyframes.set(rule.name(), move(keyframe_set));