/* * Copyright (c) 2024, MacDue * Copyright (c) 2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::CSS { struct Inset { Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; void serialize(StringBuilder&, SerializationMode) const; bool operator==(Inset const&) const = default; bool is_computationally_independent() const { return top->is_computationally_independent() && right->is_computationally_independent() && bottom->is_computationally_independent() && left->is_computationally_independent() && border_radius->is_computationally_independent(); } ValueComparingNonnullRefPtr top; ValueComparingNonnullRefPtr right; ValueComparingNonnullRefPtr bottom; ValueComparingNonnullRefPtr left; ValueComparingNonnullRefPtr border_radius; }; struct Xywh { void serialize(StringBuilder&, SerializationMode) const; bool operator==(Xywh const&) const = default; bool is_computationally_independent() const { return x->is_computationally_independent() && y->is_computationally_independent() && width->is_computationally_independent() && height->is_computationally_independent() && border_radius->is_computationally_independent(); } ValueComparingNonnullRefPtr x; ValueComparingNonnullRefPtr y; ValueComparingNonnullRefPtr width; ValueComparingNonnullRefPtr height; ValueComparingNonnullRefPtr border_radius; }; struct Rect { void serialize(StringBuilder&, SerializationMode) const; bool operator==(Rect const&) const = default; bool is_computationally_independent() const { return top->is_computationally_independent() && right->is_computationally_independent() && bottom->is_computationally_independent() && left->is_computationally_independent() && border_radius->is_computationally_independent(); } ValueComparingNonnullRefPtr top; ValueComparingNonnullRefPtr right; ValueComparingNonnullRefPtr bottom; ValueComparingNonnullRefPtr left; ValueComparingNonnullRefPtr border_radius; }; struct Circle { Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; void serialize(StringBuilder&, SerializationMode) const; bool operator==(Circle const&) const = default; bool is_computationally_independent() const { return radius->is_computationally_independent() && (!position || position->is_computationally_independent()); } ValueComparingNonnullRefPtr radius; ValueComparingRefPtr position; }; struct Ellipse { Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; void serialize(StringBuilder&, SerializationMode) const; bool operator==(Ellipse const&) const = default; bool is_computationally_independent() const { return radius->is_computationally_independent() && (!position || position->is_computationally_independent()); } ValueComparingNonnullRefPtr radius; ValueComparingRefPtr position; }; struct Polygon { struct Point { bool operator==(Point const&) const = default; ValueComparingNonnullRefPtr x; ValueComparingNonnullRefPtr y; }; Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; void serialize(StringBuilder&, SerializationMode) const; bool operator==(Polygon const&) const = default; bool is_computationally_independent() const { return all_of(points, [](Point const& point) { return point.x->is_computationally_independent() && point.y->is_computationally_independent(); }); } Gfx::WindingRule fill_rule; Vector points; }; // https://drafts.csswg.org/css-shapes/#funcdef-basic-shape-path struct Path { Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; void serialize(StringBuilder&, SerializationMode) const; bool operator==(Path const&) const = default; bool is_computationally_independent() const { return true; } Gfx::WindingRule fill_rule; SVG::Path path_instructions; }; // https://www.w3.org/TR/css-shapes-1/#basic-shape-functions using BasicShape = Variant; class BasicShapeStyleValue : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(BasicShape basic_shape) { return adopt_ref(*new (nothrow) BasicShapeStyleValue(move(basic_shape))); } virtual ~BasicShapeStyleValue() override; BasicShape const& basic_shape() const { return m_basic_shape; } virtual void serialize(StringBuilder&, SerializationMode) const override; virtual ValueComparingNonnullRefPtr absolutized(ComputationContext const&) const override; bool properties_equal(BasicShapeStyleValue const& other) const { return m_basic_shape == other.m_basic_shape; } virtual bool is_computationally_independent() const override { return m_basic_shape.visit([](auto const& shape) { return shape.is_computationally_independent(); }); } Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const; private: BasicShapeStyleValue(BasicShape basic_shape) : StyleValueWithDefaultOperators(Type::BasicShape) , m_basic_shape(move(basic_shape)) { } BasicShape m_basic_shape; }; }