mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Clamp calculated cubic-bezier() X coords using normal system
Previously we were doing this ad-hoc later in the process but we now have the `calc` clamping system which can simplify things
This commit is contained in:
parent
ef4f01ea44
commit
06a57a280d
|
|
@ -312,9 +312,9 @@ EasingFunction EasingFunction::from_style_value(StyleValue const& style_value)
|
||||||
return LinearEasingFunction { resolved_control_points, linear.to_string(SerializationMode::ResolvedValue) };
|
return LinearEasingFunction { resolved_control_points, linear.to_string(SerializationMode::ResolvedValue) };
|
||||||
},
|
},
|
||||||
[](EasingStyleValue::CubicBezier const& cubic_bezier) -> EasingFunction {
|
[](EasingStyleValue::CubicBezier const& cubic_bezier) -> EasingFunction {
|
||||||
auto resolved_x1 = clamp(cubic_bezier.x1.resolved({}).value_or(0.0), 0.0, 1.0);
|
auto resolved_x1 = cubic_bezier.x1.resolved({}).value_or(0.0);
|
||||||
auto resolved_y1 = cubic_bezier.y1.resolved({}).value_or(0.0);
|
auto resolved_y1 = cubic_bezier.y1.resolved({}).value_or(0.0);
|
||||||
auto resolved_x2 = clamp(cubic_bezier.x2.resolved({}).value_or(0.0), 0.0, 1.0);
|
auto resolved_x2 = cubic_bezier.x2.resolved({}).value_or(0.0);
|
||||||
auto resolved_y2 = cubic_bezier.y2.resolved({}).value_or(0.0);
|
auto resolved_y2 = cubic_bezier.y2.resolved({}).value_or(0.0);
|
||||||
|
|
||||||
return CubicBezierEasingFunction { resolved_x1, resolved_y1, resolved_x2, resolved_y2, cubic_bezier.to_string(SerializationMode::Normal) };
|
return CubicBezierEasingFunction { resolved_x1, resolved_y1, resolved_x2, resolved_y2, cubic_bezier.to_string(SerializationMode::Normal) };
|
||||||
|
|
|
||||||
|
|
@ -566,6 +566,7 @@ private:
|
||||||
};
|
};
|
||||||
enum SpecialContext : u8 {
|
enum SpecialContext : u8 {
|
||||||
AngularColorStopList,
|
AngularColorStopList,
|
||||||
|
CubicBezierFunctionXCoordinate,
|
||||||
ShadowBlurRadius,
|
ShadowBlurRadius,
|
||||||
TranslateZArgument
|
TranslateZArgument
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2957,9 +2957,12 @@ RefPtr<StyleValue const> Parser::parse_easing_value(TokenStream<ComponentValue>&
|
||||||
return parse_number(argument_tokens);
|
return parse_number(argument_tokens);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_value_context.append(SpecialContext::CubicBezierFunctionXCoordinate);
|
||||||
auto x1 = parse_argument(0);
|
auto x1 = parse_argument(0);
|
||||||
auto y1 = parse_argument(1);
|
|
||||||
auto x2 = parse_argument(2);
|
auto x2 = parse_argument(2);
|
||||||
|
m_value_context.take_last();
|
||||||
|
|
||||||
|
auto y1 = parse_argument(1);
|
||||||
auto y2 = parse_argument(3);
|
auto y2 = parse_argument(3);
|
||||||
if (!x1.has_value() || !y1.has_value() || !x2.has_value() || !y2.has_value())
|
if (!x1.has_value() || !y1.has_value() || !x2.has_value() || !y2.has_value())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -4136,6 +4139,9 @@ RefPtr<CalculatedStyleValue const> Parser::parse_calculated_value(ComponentValue
|
||||||
switch (special_context) {
|
switch (special_context) {
|
||||||
case SpecialContext::AngularColorStopList:
|
case SpecialContext::AngularColorStopList:
|
||||||
return CalculationContext { .percentages_resolve_as = ValueType::Angle };
|
return CalculationContext { .percentages_resolve_as = ValueType::Angle };
|
||||||
|
case SpecialContext::CubicBezierFunctionXCoordinate:
|
||||||
|
// Coordinates on the X axis must be between 0 and 1
|
||||||
|
return CalculationContext { .accepted_type_ranges = { { ValueType::Number, { 0, 1 } } } };
|
||||||
case SpecialContext::ShadowBlurRadius:
|
case SpecialContext::ShadowBlurRadius:
|
||||||
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
|
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
|
||||||
case SpecialContext::TranslateZArgument:
|
case SpecialContext::TranslateZArgument:
|
||||||
|
|
|
||||||
|
|
@ -116,18 +116,7 @@ String EasingStyleValue::CubicBezier::to_string(SerializationMode mode) const
|
||||||
} else if (*this == CubicBezier::ease_in_out()) {
|
} else if (*this == CubicBezier::ease_in_out()) {
|
||||||
builder.append("ease-in-out"sv);
|
builder.append("ease-in-out"sv);
|
||||||
} else {
|
} else {
|
||||||
auto x1_value = x1;
|
builder.appendff("cubic-bezier({}, {}, {}, {})", x1.to_string(mode), y1.to_string(mode), x2.to_string(mode), y2.to_string(mode));
|
||||||
auto y1_value = y1;
|
|
||||||
auto x2_value = x2;
|
|
||||||
auto y2_value = y2;
|
|
||||||
if (mode == SerializationMode::ResolvedValue) {
|
|
||||||
x1_value = clamp(x1_value.resolved({}).value_or(0.0), 0.0, 1.0);
|
|
||||||
x2_value = clamp(x2_value.resolved({}).value_or(0.0), 0.0, 1.0);
|
|
||||||
y1_value = y1_value.resolved({}).value_or(0.0);
|
|
||||||
y2_value = y2_value.resolved({}).value_or(0.0);
|
|
||||||
}
|
|
||||||
builder.appendff("cubic-bezier({}, {}, {}, {})",
|
|
||||||
x1_value.to_string(mode), y1_value.to_string(mode), x2_value.to_string(mode), y2_value.to_string(mode));
|
|
||||||
}
|
}
|
||||||
return MUST(builder.to_string());
|
return MUST(builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user