1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:17:35 +00:00

LibWeb: Give <svg> elements a size again

This replaces the unused width() and height() methods. The size now
defaults to 100% by 100% as in the spec.
This commit is contained in:
Sam Atkins 2022-02-15 16:42:00 +00:00 committed by Andreas Kling
parent d159511d85
commit ae93aeb414
2 changed files with 15 additions and 8 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibGfx/Painter.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
@ -24,14 +25,21 @@ RefPtr<Layout::Node> SVGSVGElement::create_layout_node(NonnullRefPtr<CSS::StyleP
return adopt_ref(*new Layout::SVGSVGBox(document(), *this, move(style)));
}
unsigned SVGSVGElement::width() const
void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
return attribute(HTML::AttributeNames::width).to_uint().value_or(300);
}
// Width defaults to 100%
if (auto width_value = parse_html_length(document(), attribute("width"))) {
style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
} else {
style.set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
}
unsigned SVGSVGElement::height() const
{
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
// Height defaults to 100%
if (auto height_value = parse_html_length(document(), attribute("height"))) {
style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
} else {
style.set_property(CSS::PropertyID::Height, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
}
}
void SVGSVGElement::parse_attribute(FlyString const& name, String const& value)