2020-07-19 23:01:53 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
|
2022-07-11 12:26:53 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2020-07-19 23:01:53 -07:00
|
|
|
*
|
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>
|
2022-03-26 14:29:52 +01:00
|
|
|
#include <LibWeb/HTML/Parser/HTMLParser.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
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
SVGSVGElement::SVGSVGElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2020-10-10 02:48:05 +01:00
|
|
|
: SVGGraphicsElement(document, qualified_name)
|
2020-07-19 23:01:53 -07:00
|
|
|
{
|
2022-09-25 18:04:39 -06:00
|
|
|
set_prototype(&Bindings::cached_web_prototype(realm(), "SVGSVGElement"));
|
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-07-11 12:26:53 +02:00
|
|
|
auto width_attribute = attribute(SVG::AttributeNames::width);
|
|
|
|
if (auto width_value = HTML::parse_dimension_value(width_attribute)) {
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
|
2022-07-11 12:26:53 +02:00
|
|
|
} else if (width_attribute == "") {
|
|
|
|
// If the `width` attribute is an empty string, it defaults to 100%.
|
|
|
|
// This matches WebKit and Blink, but not Firefox. The spec is unclear.
|
|
|
|
// FIXME: Figure out what to do here.
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage { 100 }));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Height defaults to 100%
|
2022-07-11 12:26:53 +02:00
|
|
|
auto height_attribute = attribute(SVG::AttributeNames::height);
|
|
|
|
if (auto height_value = HTML::parse_dimension_value(height_attribute)) {
|
2022-02-15 16:42:00 +00:00
|
|
|
style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
|
2022-07-11 12:26:53 +02:00
|
|
|
} else if (height_attribute == "") {
|
|
|
|
// If the `height` attribute is an empty string, it defaults to 100%.
|
|
|
|
// This matches WebKit and Blink, but not Firefox. The spec is unclear.
|
|
|
|
// FIXME: Figure out what to do here.
|
2022-02-15 16:42:00 +00:00
|
|
|
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
|
|
|
}
|