mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
LibWeb: Maintain easing keywords as KeywordStyleValue until use-time
This excludes `step-end` and `step-start` which are expected to be converted to the equivalent function at parse time. We are expected to serialize these as the explicit keywords - previously we would parse as `EasingStyleValue` and serialize equivalent functions as the keywords. This caused issues as we would incorrectly serialize even explicit functions as the keyword. This also allows us to move the magic easing functions to `EasingFunction` rather than `EasingStyleValue` which is a bit tidier
This commit is contained in:
Notes:
github-actions[bot]
2025-10-20 10:29:02 +00:00
Author: https://github.com/Calme1709 Commit: https://github.com/LadybirdBrowser/ladybird/commit/03be70087d4 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6459 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -8,6 +8,7 @@
|
||||
#include <AK/BinarySearch.h>
|
||||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
|
||||
@@ -268,6 +269,41 @@ static Vector<LinearEasingFunction::ControlPoint> canonicalize_linear_easing_fun
|
||||
return canonicalized_control_points;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-easing-2/#linear-easing-function
|
||||
EasingFunction EasingFunction::linear()
|
||||
{
|
||||
// Equivalent to linear(0, 1)
|
||||
return LinearEasingFunction { { { 0, 0 }, { 1, 1 } }, "linear"_string };
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-easing-2/#valdef-cubic-bezier-easing-function-ease-in
|
||||
EasingFunction EasingFunction::ease_in()
|
||||
{
|
||||
// Equivalent to cubic-bezier(0.42, 0, 1, 1).
|
||||
return CubicBezierEasingFunction { 0.42, 0, 1, 1, "ease-in"_string };
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-easing-2/#valdef-cubic-bezier-easing-function-ease-out
|
||||
EasingFunction EasingFunction::ease_out()
|
||||
{
|
||||
// Equivalent to cubic-bezier(0, 0, 0.58, 1).
|
||||
return CubicBezierEasingFunction { 0, 0, 0.58, 1, "ease-out"_string };
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-easing-2/#valdef-cubic-bezier-easing-function-ease-in-out
|
||||
EasingFunction EasingFunction::ease_in_out()
|
||||
{
|
||||
// Equivalent to cubic-bezier(0.42, 0, 0.58, 1).
|
||||
return CubicBezierEasingFunction { 0.42, 0, 0.58, 1, "ease-in-out"_string };
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-easing-2/#valdef-cubic-bezier-easing-function-ease
|
||||
EasingFunction EasingFunction::ease()
|
||||
{
|
||||
// Equivalent to cubic-bezier(0.25, 0.1, 0.25, 1).
|
||||
return CubicBezierEasingFunction { 0.25, 0.1, 0.25, 1, "ease"_string };
|
||||
}
|
||||
|
||||
EasingFunction EasingFunction::from_style_value(StyleValue const& style_value)
|
||||
{
|
||||
auto const resolve_number = [](StyleValue const& style_value) {
|
||||
@@ -335,6 +371,22 @@ EasingFunction EasingFunction::from_style_value(StyleValue const& style_value)
|
||||
});
|
||||
}
|
||||
|
||||
switch (style_value.to_keyword()) {
|
||||
case Keyword::Linear:
|
||||
return EasingFunction::linear();
|
||||
case Keyword::EaseIn:
|
||||
return EasingFunction::ease_in();
|
||||
case Keyword::EaseOut:
|
||||
return EasingFunction::ease_out();
|
||||
case Keyword::EaseInOut:
|
||||
return EasingFunction::ease_in_out();
|
||||
case Keyword::Ease:
|
||||
return EasingFunction::ease();
|
||||
default: {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user