diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 5989040f1a6..dcb91245f0e 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -234,18 +235,31 @@ private: }; // https://drafts.fxtf.org/css-masking/#the-clip-path +// TODO: Support clip sources. class ClipPathReference { public: - // TODO: Support clip sources. ClipPathReference(URL::URL const& url) - : m_url(url) + : m_clip_source(url) { } - URL::URL const& url() const { return m_url; } + ClipPathReference(BasicShapeStyleValue const& basic_shape) + : m_clip_source(basic_shape) + { + } + + bool is_basic_shape() const { return m_clip_source.has(); } + + bool is_url() const { return m_clip_source.has(); } + + URL::URL const& url() const { return m_clip_source.get(); } + + BasicShapeStyleValue const& basic_shape() const { return *m_clip_source.get(); } private: - URL::URL m_url; + using BasicShape = NonnullRefPtr; + + Variant m_clip_source; }; struct BackgroundLayerData { diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 4080938a2b8..bdb51f6678b 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -712,6 +712,7 @@ ], "__comment": "FIXME: This should be a | [ || ]", "valid-types": [ + "basic-shape", "url" ], "initial": "none" diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index e9cef051b60..27c728187e3 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -801,8 +801,11 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto mask = computed_style.property(CSS::PropertyID::Mask); mask->is_url()) computed_values.set_mask(mask->as_url().url()); - if (auto clip_path = computed_style.property(CSS::PropertyID::ClipPath); clip_path->is_url()) + auto clip_path = computed_style.property(CSS::PropertyID::ClipPath); + if (clip_path->is_url()) computed_values.set_clip_path(clip_path->as_url().url()); + else if (clip_path->is_basic_shape()) + computed_values.set_clip_path(clip_path->as_basic_shape()); if (auto clip_rule = computed_style.clip_rule(); clip_rule.has_value()) computed_values.set_clip_rule(*clip_rule); diff --git a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp index 50a3f3856ab..af86377b49f 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp @@ -83,7 +83,7 @@ JS::GCPtr SVGGraphicsElement::mask() const JS::GCPtr SVGGraphicsElement::clip_path() const { auto const& clip_path_reference = layout_node()->computed_values().clip_path(); - if (!clip_path_reference.has_value()) + if (!clip_path_reference.has_value() || !clip_path_reference->is_url()) return {}; return try_resolve_url_to(clip_path_reference->url()); }