Skip to content

Commit

Permalink
WIP: Pass PropertyID through the interpolation functions
Browse files Browse the repository at this point in the history
Will probably merge this with another commit.
  • Loading branch information
AtkinsSJ committed Jan 8, 2025
1 parent 33d36c4 commit 80754e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
30 changes: 15 additions & 15 deletions Libraries/LibWeb/CSS/Interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ ValueComparingRefPtr<CSSStyleValue const> interpolate_property(DOM::Element& ele
auto animation_type = animation_type_from_longhand_property(property_id);
switch (animation_type) {
case AnimationType::ByComputedValue:
return interpolate_value(element, from, to, delta);
return interpolate_value(element, property_id, from, to, delta);
case AnimationType::None:
return to;
case AnimationType::Custom: {
if (property_id == PropertyID::Transform) {
if (auto interpolated_transform = interpolate_transform(element, from, to, delta))
if (auto interpolated_transform = interpolate_transform(element, property_id, from, to, delta))
return *interpolated_transform;

// https://drafts.csswg.org/css-transforms-1/#interpolation-of-transforms
Expand All @@ -78,7 +78,7 @@ ValueComparingRefPtr<CSSStyleValue const> interpolate_property(DOM::Element& ele
return {};
}
if (property_id == PropertyID::BoxShadow)
return interpolate_box_shadow(element, from, to, delta);
return interpolate_box_shadow(element, property_id, from, to, delta);

// FIXME: Handle all custom animatable properties
[[fallthrough]];
Expand Down Expand Up @@ -108,7 +108,7 @@ bool property_values_are_transitionable(PropertyID property_id, CSSStyleValue co
}

// A null return value means the interpolated matrix was not invertible or otherwise invalid
RefPtr<CSSStyleValue const> interpolate_transform(DOM::Element& element, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
RefPtr<CSSStyleValue const> interpolate_transform(DOM::Element& element, PropertyID, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
{
// Note that the spec uses column-major notation, so all the matrix indexing is reversed.

Expand Down Expand Up @@ -422,7 +422,7 @@ Color interpolate_color(Color from, Color to, float delta)
return color;
}

NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element& element, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element& element, PropertyID property_id, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
{
// https://drafts.csswg.org/css-backgrounds/#box-shadow
// Animation type: by computed value, treating none as a zero-item list and appending blank shadows
Expand Down Expand Up @@ -472,18 +472,18 @@ NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element& element,
auto const& to_shadow = to_shadows[i]->as_shadow();
auto result_shadow = ShadowStyleValue::create(
CSSColorValue::create_from_color(interpolate_color(from_shadow.color()->to_color({}), to_shadow.color()->to_color({}), delta)),
interpolate_value(element, from_shadow.offset_x(), to_shadow.offset_x(), delta),
interpolate_value(element, from_shadow.offset_y(), to_shadow.offset_y(), delta),
interpolate_value(element, from_shadow.blur_radius(), to_shadow.blur_radius(), delta),
interpolate_value(element, from_shadow.spread_distance(), to_shadow.spread_distance(), delta),
interpolate_value(element, property_id, from_shadow.offset_x(), to_shadow.offset_x(), delta),
interpolate_value(element, property_id, from_shadow.offset_y(), to_shadow.offset_y(), delta),
interpolate_value(element, property_id, from_shadow.blur_radius(), to_shadow.blur_radius(), delta),
interpolate_value(element, property_id, from_shadow.spread_distance(), to_shadow.spread_distance(), delta),
delta >= 0.5f ? to_shadow.placement() : from_shadow.placement());
result_shadows.unchecked_append(result_shadow);
}

return StyleValueList::create(move(result_shadows), StyleValueList::Separator::Comma);
}

NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& element, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& element, PropertyID property_id, CSSStyleValue const& from, CSSStyleValue const& to, float delta)
{
if (from.type() != to.type()) {
// Handle mixed percentage and dimension types
Expand Down Expand Up @@ -546,8 +546,8 @@ NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& element, CSSS
// hard to understand how this interpolation works, but if instead we rewrite the values as "30px + 0%" and
// "0px + 80%", then it is very simple to understand; we just interpolate each component separately.

auto interpolated_from = interpolate_value(element, from, from_base_type_and_default->default_value, delta);
auto interpolated_to = interpolate_value(element, to_base_type_and_default->default_value, to, delta);
auto interpolated_from = interpolate_value(element, property_id, from, from_base_type_and_default->default_value, delta);
auto interpolated_to = interpolate_value(element, property_id, to_base_type_and_default->default_value, to, delta);

Vector<NonnullOwnPtr<CalculationNode>> values;
values.ensure_capacity(2);
Expand Down Expand Up @@ -587,8 +587,8 @@ NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& element, CSSS
auto const& from_position = from.as_position();
auto const& to_position = to.as_position();
return PositionStyleValue::create(
interpolate_value(element, from_position.edge_x(), to_position.edge_x(), delta)->as_edge(),
interpolate_value(element, from_position.edge_y(), to_position.edge_y(), delta)->as_edge());
interpolate_value(element, property_id, from_position.edge_x(), to_position.edge_x(), delta)->as_edge(),
interpolate_value(element, property_id, from_position.edge_y(), to_position.edge_y(), delta)->as_edge());
}
case CSSStyleValue::Type::Ratio: {
auto from_ratio = from.as_ratio().ratio();
Expand Down Expand Up @@ -634,7 +634,7 @@ NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& element, CSSS
StyleValueVector interpolated_values;
interpolated_values.ensure_capacity(from_list.size());
for (size_t i = 0; i < from_list.size(); ++i)
interpolated_values.append(interpolate_value(element, from_list.values()[i], to_list.values()[i], delta));
interpolated_values.append(interpolate_value(element, property_id, from_list.values()[i], to_list.values()[i], delta));

return StyleValueList::create(move(interpolated_values), from_list.separator());
}
Expand Down
6 changes: 3 additions & 3 deletions Libraries/LibWeb/CSS/Interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ValueComparingRefPtr<CSSStyleValue const> interpolate_property(DOM::Element&, Pr
// https://drafts.csswg.org/css-transitions/#transitionable
bool property_values_are_transitionable(PropertyID, CSSStyleValue const& old_value, CSSStyleValue const& new_value);

NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element&, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element&, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
RefPtr<CSSStyleValue const> interpolate_transform(DOM::Element&, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element&, PropertyID, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element&, PropertyID, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
RefPtr<CSSStyleValue const> interpolate_transform(DOM::Element&, PropertyID, CSSStyleValue const& from, CSSStyleValue const& to, float delta);

Color interpolate_color(Color from, Color to, float delta);

Expand Down

0 comments on commit 80754e1

Please sign in to comment.