BasicShapeStyleValue.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2024, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Variant.h>
  8. #include <LibGfx/DeprecatedPath.h>
  9. #include <LibWeb/CSS/CSSStyleValue.h>
  10. #include <LibWeb/CSS/PercentageOr.h>
  11. namespace Web::CSS {
  12. struct Polygon {
  13. struct Point {
  14. bool operator==(Point const&) const = default;
  15. LengthPercentage x;
  16. LengthPercentage y;
  17. };
  18. Gfx::DeprecatedPath to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  19. String to_string() const;
  20. bool operator==(Polygon const&) const = default;
  21. FillRule fill_rule;
  22. Vector<Point> points;
  23. };
  24. // FIXME: Implement other basic shapes. See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions
  25. using BasicShape = Variant<Polygon>;
  26. class BasicShapeStyleValue : public StyleValueWithDefaultOperators<BasicShapeStyleValue> {
  27. public:
  28. static ValueComparingNonnullRefPtr<BasicShapeStyleValue> create(BasicShape basic_shape)
  29. {
  30. return adopt_ref(*new (nothrow) BasicShapeStyleValue(move(basic_shape)));
  31. }
  32. virtual ~BasicShapeStyleValue() override;
  33. BasicShape const& basic_shape() const { return m_basic_shape; }
  34. virtual String to_string() const override;
  35. bool properties_equal(BasicShapeStyleValue const& other) const { return m_basic_shape == other.m_basic_shape; }
  36. Gfx::DeprecatedPath to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  37. private:
  38. BasicShapeStyleValue(BasicShape basic_shape)
  39. : StyleValueWithDefaultOperators(Type::BasicShape)
  40. , m_basic_shape(move(basic_shape))
  41. {
  42. }
  43. BasicShape m_basic_shape;
  44. };
  45. }