LibWeb: Add (and use) CSS property to SVGAnimatedLength helper

No behaviour change.
This commit is contained in:
MacDue 2024-04-01 00:40:26 +01:00 committed by Alexander Kalenik
commit d2918b8204
Notes: sideshowbarker 2024-07-17 09:48:50 +09:00
3 changed files with 19 additions and 27 deletions

View file

@ -7,6 +7,7 @@
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/DOMStringMap.h>
@ -107,4 +108,17 @@ void SVGElement::blur()
dbgln("(STUBBED) SVGElement::blur()");
}
JS::NonnullGCPtr<SVGAnimatedLength> SVGElement::svg_animated_length_for_property(CSS::PropertyID property) const
{
// FIXME: Create a proper animated value when animations are supported.
auto make_length = [&] {
if (auto const* style = computed_css_values(); style) {
if (auto length = style->length_percentage(property); length.has_value())
return SVGLength::from_length_percentage(realm(), *length);
}
return SVGLength::create(realm(), 0, 0.0f);
};
return SVGAnimatedLength::create(realm(), make_length(), make_length());
}
}