BasicShapeStyleValue.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <LibWeb/CSS/CSSStyleValue.h>
  9. #include <LibWeb/CSS/LengthBox.h>
  10. #include <LibWeb/CSS/PercentageOr.h>
  11. #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
  12. namespace Web::CSS {
  13. struct Inset {
  14. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  15. String to_string() const;
  16. bool operator==(Inset const&) const = default;
  17. LengthBox inset_box;
  18. };
  19. struct Xywh {
  20. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  21. String to_string() const;
  22. bool operator==(Xywh const&) const = default;
  23. LengthPercentage x;
  24. LengthPercentage y;
  25. LengthPercentage width;
  26. LengthPercentage height;
  27. };
  28. struct Rect {
  29. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  30. String to_string() const;
  31. bool operator==(Rect const&) const = default;
  32. LengthBox box;
  33. };
  34. enum class FitSide {
  35. ClosestSide,
  36. FarthestSide,
  37. };
  38. using ShapeRadius = Variant<LengthPercentage, FitSide>;
  39. struct Circle {
  40. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  41. String to_string() const;
  42. bool operator==(Circle const&) const = default;
  43. ShapeRadius radius;
  44. ValueComparingNonnullRefPtr<PositionStyleValue> position;
  45. };
  46. struct Ellipse {
  47. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  48. String to_string() const;
  49. bool operator==(Ellipse const&) const = default;
  50. ShapeRadius radius_x;
  51. ShapeRadius radius_y;
  52. ValueComparingNonnullRefPtr<PositionStyleValue> position;
  53. };
  54. struct Polygon {
  55. struct Point {
  56. bool operator==(Point const&) const = default;
  57. LengthPercentage x;
  58. LengthPercentage y;
  59. };
  60. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  61. String to_string() const;
  62. bool operator==(Polygon const&) const = default;
  63. // FIXME: Actually use the fill rule
  64. FillRule fill_rule;
  65. Vector<Point> points;
  66. };
  67. // FIXME: Implement path(). See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions
  68. using BasicShape = Variant<Inset, Xywh, Rect, Circle, Ellipse, Polygon>;
  69. class BasicShapeStyleValue : public StyleValueWithDefaultOperators<BasicShapeStyleValue> {
  70. public:
  71. static ValueComparingNonnullRefPtr<BasicShapeStyleValue> create(BasicShape basic_shape)
  72. {
  73. return adopt_ref(*new (nothrow) BasicShapeStyleValue(move(basic_shape)));
  74. }
  75. virtual ~BasicShapeStyleValue() override;
  76. BasicShape const& basic_shape() const { return m_basic_shape; }
  77. virtual String to_string() const override;
  78. bool properties_equal(BasicShapeStyleValue const& other) const { return m_basic_shape == other.m_basic_shape; }
  79. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  80. private:
  81. BasicShapeStyleValue(BasicShape basic_shape)
  82. : StyleValueWithDefaultOperators(Type::BasicShape)
  83. , m_basic_shape(move(basic_shape))
  84. {
  85. }
  86. BasicShape m_basic_shape;
  87. };
  88. }