/src/serenity/Userland/Libraries/LibWeb/SVG/SVGMaskElement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/SVG/AttributeParser.h> |
10 | | #include <LibWeb/SVG/SVGGraphicsElement.h> |
11 | | #include <LibWeb/SVG/SVGViewport.h> |
12 | | |
13 | | namespace Web::SVG { |
14 | | |
15 | | class SVGMaskElement final : public SVGGraphicsElement |
16 | | , public SVGViewport { |
17 | | |
18 | | WEB_PLATFORM_OBJECT(SVGMaskElement, SVGGraphicsElement); |
19 | | JS_DECLARE_ALLOCATOR(SVGMaskElement); |
20 | | |
21 | | public: |
22 | | virtual ~SVGMaskElement() override; |
23 | | |
24 | | virtual Optional<ViewBox> view_box() const override |
25 | 0 | { |
26 | | // maskContentUnits = objectBoundingBox acts like the mask is sized to the bounding box |
27 | | // of the target element, with a viewBox of "0 0 1 1". |
28 | 0 | if (mask_content_units() == MaskContentUnits::ObjectBoundingBox) |
29 | 0 | return ViewBox { 0, 0, 1, 1 }; |
30 | 0 | return {}; |
31 | 0 | } |
32 | | |
33 | | virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const override |
34 | 0 | { |
35 | | // preserveAspectRatio = none (allow mask to be scaled in both x and y to match target size) |
36 | 0 | return PreserveAspectRatio { PreserveAspectRatio::Align::None, {} }; |
37 | 0 | } |
38 | | |
39 | | virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override; |
40 | | |
41 | | virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; |
42 | | |
43 | | CSSPixelRect resolve_masking_area(CSSPixelRect const& mask_target) const; |
44 | | |
45 | | MaskContentUnits mask_content_units() const; |
46 | | MaskUnits mask_units() const; |
47 | | |
48 | | private: |
49 | | SVGMaskElement(DOM::Document&, DOM::QualifiedName); |
50 | | virtual void initialize(JS::Realm&) override; |
51 | | |
52 | | Optional<MaskContentUnits> m_mask_content_units = {}; |
53 | | Optional<MaskUnits> m_mask_units = {}; |
54 | | }; |
55 | | |
56 | | } |