diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-15 16:42:00 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-16 21:47:53 +0100 |
commit | ae93aeb414334e5bb58517279783c01b95c74ca9 (patch) | |
tree | e91fb97990473ef3bac36a1e728f725defd01624 /Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp | |
parent | d159511d8505947f31214b6c9fed08bb6c45983f (diff) | |
download | serenity-ae93aeb414334e5bb58517279783c01b95c74ca9.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp index f7583076a0..df0e3b937a 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGSVGElement.cpp @@ -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); -} - -unsigned SVGSVGElement::height() const -{ - return attribute(HTML::AttributeNames::height).to_uint().value_or(150); + // 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 })); + } + + // 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) |