2020-07-19 23:01:53 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-19 23:01:53 -07:00
|
|
|
*/
|
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibGfx/Painter.h>
|
2022-02-15 16:42:00 +00:00
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2021-09-24 13:49:57 +02:00
|
|
|
#include <LibWeb/CSS/StyleComputer.h>
|
2020-07-19 23:01:53 -07:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
2021-09-15 01:12:41 +02:00
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/SVGSVGElement.h>
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
namespace Web::SVG {
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2021-02-07 11:20:15 +01:00
|
|
|
SVGSVGElement::SVGSVGElement(DOM::Document& document, QualifiedName qualified_name)
|
2020-10-10 02:48:05 +01:00
|
|
|
: SVGGraphicsElement(document, qualified_name)
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-05 13:17:01 +01:00
|
|
|
RefPtr<Layout::Node> SVGSVGElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2021-04-23 16:46:57 +02:00
|
|
|
return adopt_ref(*new Layout::SVGSVGBox(document(), *this, move(style)));
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|
|
|
|
|
2022-02-15 16:42:00 +00:00
|
|
|
void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2022-02-15 16:42:00 +00:00
|
|
|
// 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 }));
|
|
|
|
}
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|
|
|
|
|
2021-09-15 01:12:41 +02:00
|
|
|
void SVGSVGElement::parse_attribute(FlyString const& name, String const& value)
|
|
|
|
{
|
|
|
|
SVGGraphicsElement::parse_attribute(name, value);
|
|
|
|
|
|
|
|
if (name.equals_ignoring_case(SVG::AttributeNames::viewBox))
|
|
|
|
m_view_box = try_parse_view_box(value);
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:01:53 -07:00
|
|
|
}
|