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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibGfx/Bitmap.h>
|
2024-04-01 00:51:24 +01:00
|
|
|
#include <LibWeb/DOM/NonElementParentNode.h>
|
|
|
|
|
#include <LibWeb/Geometry/DOMMatrix.h>
|
|
|
|
|
#include <LibWeb/Geometry/DOMPoint.h>
|
2023-04-17 01:20:24 +01:00
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
2024-04-01 00:51:24 +01:00
|
|
|
#include <LibWeb/SVG/SVGAnimatedLength.h>
|
2020-07-23 09:44:42 -07:00
|
|
|
#include <LibWeb/SVG/SVGGraphicsElement.h>
|
2024-04-01 00:51:24 +01:00
|
|
|
#include <LibWeb/SVG/SVGLength.h>
|
|
|
|
|
#include <LibWeb/SVG/SVGTransform.h>
|
2024-01-27 16:23:22 +00:00
|
|
|
#include <LibWeb/SVG/SVGViewport.h>
|
2021-09-15 01:12:41 +02:00
|
|
|
#include <LibWeb/SVG/ViewBox.h>
|
2024-04-01 00:51:24 +01:00
|
|
|
#include <LibWeb/WebIDL/Types.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-01-27 16:23:22 +00:00
|
|
|
class SVGSVGElement final : public SVGGraphicsElement
|
2024-04-01 00:51:24 +01:00
|
|
|
, public SVGViewport
|
|
|
|
|
// SVGSVGElement is not strictly a NonElementParentNode, but it implements the same get_element_by_id() method.
|
|
|
|
|
, public DOM::NonElementParentNode<SVGSVGElement> {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(SVGSVGElement, SVGGraphicsElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(SVGSVGElement);
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2024-12-20 16:35:12 +01:00
|
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2024-12-23 17:51:10 +01:00
|
|
|
virtual bool is_presentational_hint(FlyString const&) const override;
|
LibWeb: Split StyleComputer work into two phases with separate outputs
Before this change, StyleComputer would essentially take a DOM element,
find all the CSS rules that apply to it, and resolve the computed value
for each CSS property for that element.
This worked great, but it meant we had to do all the work of selector
matching and cascading every time.
To enable new optimizations, this change introduces a break in the
middle of this process where we've produced a "CascadedProperties".
This object contains the result of the cascade, before we've begun
turning cascaded values into computed values.
The cascaded properties are now stored with each element, which will
later allow us to do partial updates without re-running the full
StyleComputer machine. This will be particularly valuable for
re-implementing CSS inheritance, which is extremely heavy today.
Note that CSS animations and CSS transitions operate entirely on the
computed values, even though the cascade order would have you believe
they happen earlier. I'm not confident we have the right architecture
for this, but that's a separate issue.
2024-12-12 10:06:29 +01:00
|
|
|
virtual void apply_presentational_hints(GC::Ref<CSS::CascadedProperties>) const override;
|
2020-07-19 23:01:53 -07:00
|
|
|
|
2021-08-05 10:26:09 +02:00
|
|
|
virtual bool requires_svg_container() const override { return false; }
|
|
|
|
|
virtual bool is_svg_container() const override { return true; }
|
|
|
|
|
|
2024-01-27 16:23:22 +00:00
|
|
|
virtual Optional<ViewBox> view_box() const override;
|
|
|
|
|
virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const override { return m_preserve_aspect_ratio; }
|
2021-09-15 01:12:41 +02:00
|
|
|
|
2023-06-20 09:39:14 +02:00
|
|
|
void set_fallback_view_box_for_svg_as_image(Optional<ViewBox>);
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<SVGAnimatedRect> view_box_for_bindings() { return *m_view_box_for_bindings; }
|
2024-01-24 22:54:16 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<SVGAnimatedLength> x() const;
|
|
|
|
|
GC::Ref<SVGAnimatedLength> y() const;
|
|
|
|
|
GC::Ref<SVGAnimatedLength> width() const;
|
|
|
|
|
GC::Ref<SVGAnimatedLength> height() const;
|
2024-04-01 00:51:24 +01:00
|
|
|
|
|
|
|
|
float current_scale() const;
|
|
|
|
|
void set_current_scale(float);
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Geometry::DOMPointReadOnly> current_translate() const;
|
2024-04-01 00:51:24 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<DOM::NodeList> get_intersection_list(GC::Ref<Geometry::DOMRectReadOnly> rect, GC::Ptr<SVGElement> reference_element) const;
|
|
|
|
|
GC::Ref<DOM::NodeList> get_enclosure_list(GC::Ref<Geometry::DOMRectReadOnly> rect, GC::Ptr<SVGElement> reference_element) const;
|
|
|
|
|
bool check_intersection(GC::Ref<SVGElement> element, GC::Ref<Geometry::DOMRectReadOnly> rect) const;
|
|
|
|
|
bool check_enclosure(GC::Ref<SVGElement> element, GC::Ref<Geometry::DOMRectReadOnly> rect) const;
|
2024-04-01 00:51:24 +01:00
|
|
|
|
|
|
|
|
void deselect_all() const;
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<SVGLength> create_svg_length() const;
|
|
|
|
|
GC::Ref<Geometry::DOMPoint> create_svg_point() const;
|
|
|
|
|
GC::Ref<Geometry::DOMMatrix> create_svg_matrix() const;
|
|
|
|
|
GC::Ref<Geometry::DOMRect> create_svg_rect() const;
|
|
|
|
|
GC::Ref<SVGTransform> create_svg_transform() const;
|
2024-04-01 00:51:24 +01:00
|
|
|
|
|
|
|
|
// Deprecated methods that have no effect when called, but which are kept for compatibility reasons.
|
|
|
|
|
WebIDL::UnsignedLong suspend_redraw(WebIDL::UnsignedLong max_wait_milliseconds) const
|
|
|
|
|
{
|
|
|
|
|
(void)max_wait_milliseconds;
|
|
|
|
|
// When the suspendRedraw method is called, it must return 1.
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
void unsuspend_redraw(WebIDL::UnsignedLong suspend_handle_id) const
|
|
|
|
|
{
|
|
|
|
|
(void)suspend_handle_id;
|
|
|
|
|
}
|
2024-08-22 13:32:25 +02:00
|
|
|
void unsuspend_redraw_all() const { }
|
|
|
|
|
void force_redraw() const { }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] RefPtr<CSS::CSSStyleValue> width_style_value_from_attribute() const;
|
|
|
|
|
[[nodiscard]] RefPtr<CSS::CSSStyleValue> height_style_value_from_attribute() const;
|
2024-04-01 00:51:24 +01:00
|
|
|
|
2024-11-26 12:30:11 +01:00
|
|
|
struct NaturalMetrics {
|
|
|
|
|
Optional<CSSPixels> width;
|
|
|
|
|
Optional<CSSPixels> height;
|
|
|
|
|
Optional<CSSPixelFraction> aspect_ratio;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static NaturalMetrics negotiate_natural_metrics(SVGSVGElement const&);
|
|
|
|
|
|
2020-07-19 23:01:53 -07:00
|
|
|
private:
|
2022-08-28 13:42:07 +02:00
|
|
|
SVGSVGElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2024-01-24 22:54:16 +01:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2022-03-12 16:08:40 +01:00
|
|
|
virtual bool is_svg_svg_element() const override { return true; }
|
|
|
|
|
|
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;
|
2021-09-15 01:12:41 +02:00
|
|
|
|
2023-06-20 09:39:14 +02:00
|
|
|
void update_fallback_view_box_for_svg_as_image();
|
|
|
|
|
|
2021-09-15 01:12:41 +02:00
|
|
|
Optional<ViewBox> m_view_box;
|
2023-04-17 01:20:24 +01:00
|
|
|
Optional<PreserveAspectRatio> m_preserve_aspect_ratio;
|
2023-06-20 09:39:14 +02:00
|
|
|
|
|
|
|
|
Optional<ViewBox> m_fallback_view_box_for_svg_as_image;
|
2024-01-24 22:54:16 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SVGAnimatedRect> m_view_box_for_bindings;
|
2020-07-19 23:01:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2022-03-12 16:08:40 +01:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool Node::fast_is<SVG::SVGSVGElement>() const { return is_svg_svg_element(); }
|
|
|
|
|
|
|
|
|
|
}
|