2020-07-19 23:01:53 -07:00
|
|
|
/*
|
2021-04-22 16:53:07 -07:00
|
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
2022-01-24 15:43:44 +00:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@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
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-04-23 01:31:17 +01:00
|
|
|
#include <LibGfx/PaintStyle.h>
|
2025-04-29 15:32:46 +01:00
|
|
|
#include <LibWeb/CSS/URL.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/DOM/Node.h>
|
2023-04-10 12:25:40 +01:00
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
2024-04-01 00:49:02 +01:00
|
|
|
#include <LibWeb/SVG/SVGAnimatedTransformList.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/SVGElement.h>
|
2023-04-23 01:31:17 +01:00
|
|
|
#include <LibWeb/SVG/SVGGradientElement.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/TagNames.h>
|
2023-07-31 18:37:44 +02:00
|
|
|
#include <LibWeb/SVG/ViewBox.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
|
|
|
|
2024-04-01 00:49:02 +01:00
|
|
|
struct SVGBoundingBoxOptions {
|
|
|
|
bool fill { true };
|
|
|
|
bool stroke { false };
|
|
|
|
bool markers { false };
|
|
|
|
bool clipped { false };
|
|
|
|
};
|
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
class SVGGraphicsElement : public SVGElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2024-11-14 08:14:16 -05:00
|
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2023-04-10 12:25:00 +01:00
|
|
|
|
2021-09-16 12:28:14 +01:00
|
|
|
Optional<Gfx::Color> fill_color() const;
|
|
|
|
Optional<Gfx::Color> stroke_color() const;
|
2024-11-20 19:23:10 -05:00
|
|
|
Vector<float> stroke_dasharray() const;
|
2024-11-18 21:21:22 -05:00
|
|
|
Optional<float> stroke_dashoffset() const;
|
2021-09-16 12:28:14 +01:00
|
|
|
Optional<float> stroke_width() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
Optional<float> fill_opacity() const;
|
2024-10-10 10:15:49 -04:00
|
|
|
Optional<CSS::StrokeLinecap> stroke_linecap() const;
|
2024-10-28 20:51:16 -04:00
|
|
|
Optional<CSS::StrokeLinejoin> stroke_linejoin() const;
|
|
|
|
Optional<CSS::NumberOrCalculated> stroke_miterlimit() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
Optional<float> stroke_opacity() const;
|
2024-05-12 20:19:43 +01:00
|
|
|
Optional<FillRule> fill_rule() const;
|
|
|
|
Optional<ClipRule> clip_rule() const;
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2023-04-15 15:32:17 +01:00
|
|
|
float visible_stroke_width() const
|
|
|
|
{
|
|
|
|
if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
|
|
|
|
return stroke_width().value_or(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-10 12:25:40 +01:00
|
|
|
Gfx::AffineTransform get_transform() const;
|
|
|
|
|
2024-06-13 15:22:46 +03:00
|
|
|
Optional<Painting::PaintStyle> fill_paint_style(SVGPaintContext const&) const;
|
|
|
|
Optional<Painting::PaintStyle> stroke_paint_style(SVGPaintContext const&) const;
|
2023-04-23 01:31:17 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SVG::SVGMaskElement const> mask() const;
|
|
|
|
GC::Ptr<SVG::SVGClipPathElement const> clip_path() const;
|
2024-03-27 00:06:35 +00:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Geometry::DOMRect> get_b_box(Optional<SVGBoundingBoxOptions>);
|
|
|
|
GC::Ref<SVGAnimatedTransformList> transform() const;
|
2024-04-01 00:49:02 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Geometry::DOMMatrix> get_screen_ctm();
|
2024-11-09 18:30:38 +01:00
|
|
|
|
2023-08-31 08:58:41 +01:00
|
|
|
virtual Gfx::AffineTransform element_transform() const
|
|
|
|
{
|
|
|
|
return m_transform;
|
|
|
|
}
|
|
|
|
|
2025-01-08 14:44:00 +11:00
|
|
|
protected:
|
|
|
|
SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
|
2024-06-13 15:22:46 +03:00
|
|
|
Optional<Painting::PaintStyle> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
|
2023-06-06 20:40:10 +01:00
|
|
|
|
2023-04-10 12:25:40 +01:00
|
|
|
Gfx::AffineTransform m_transform = {};
|
2023-08-03 13:26:29 +02:00
|
|
|
|
2025-04-29 15:32:46 +01:00
|
|
|
template<typename T>
|
|
|
|
GC::Ptr<T> try_resolve_url_to(CSS::URL const& url) const
|
|
|
|
{
|
|
|
|
// FIXME: Complete and use the entire URL, not just the fragment.
|
|
|
|
Optional<FlyString> fragment;
|
|
|
|
if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
|
|
|
|
fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
|
|
|
|
}
|
|
|
|
if (!fragment.has_value())
|
|
|
|
return {};
|
|
|
|
if (auto node = document().get_element_by_id(*fragment); node && is<T>(*node))
|
|
|
|
return static_cast<T&>(*node);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-08-03 13:26:29 +02:00
|
|
|
private:
|
|
|
|
virtual bool is_svg_graphics_element() const final { return true; }
|
2024-11-18 21:21:22 -05:00
|
|
|
float resolve_relative_to_viewport_size(CSS::LengthPercentage const& length_percentage) const;
|
2020-07-19 23:01:53 -07:00
|
|
|
};
|
|
|
|
|
2023-04-12 13:32:21 -04:00
|
|
|
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
|
2023-04-10 12:25:40 +01:00
|
|
|
|
2020-07-23 09:44:42 -07:00
|
|
|
}
|
2023-08-03 13:26:29 +02:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }
|
|
|
|
|
|
|
|
}
|