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 <LibGfx/WindingRule.h>
  9. #include <LibWeb/CSS/CSSStyleValue.h>
  10. #include <LibWeb/CSS/LengthBox.h>
  11. #include <LibWeb/CSS/PercentageOr.h>
  12. #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
  13. namespace Web::CSS {
  14. struct Inset {
  15. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  16. String to_string() const;
  17. bool operator==(Inset const&) const = default;
  18. LengthBox inset_box;
  19. };
  20. struct Xywh {
  21. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  22. String to_string() const;
  23. bool operator==(Xywh const&) const = default;
  24. LengthPercentage x;
  25. LengthPercentage y;
  26. LengthPercentage width;
  27. LengthPercentage height;
  28. };
  29. struct Rect {
  30. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  31. String to_string() const;
  32. bool operator==(Rect const&) const = default;
  33. LengthBox box;
  34. };
  35. enum class FitSide {
  36. ClosestSide,
  37. FarthestSide,
  38. };
  39. using ShapeRadius = Variant<LengthPercentage, FitSide>;
  40. struct Circle {
  41. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  42. String to_string() const;
  43. bool operator==(Circle const&) const = default;
  44. ShapeRadius radius;
  45. ValueComparingNonnullRefPtr<PositionStyleValue> position;
  46. };
  47. struct Ellipse {
  48. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  49. String to_string() const;
  50. bool operator==(Ellipse const&) const = default;
  51. ShapeRadius radius_x;
  52. ShapeRadius radius_y;
  53. ValueComparingNonnullRefPtr<PositionStyleValue> position;
  54. };
  55. struct Polygon {
  56. struct Point {
  57. bool operator==(Point const&) const = default;
  58. LengthPercentage x;
  59. LengthPercentage y;
  60. };
  61. Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
  62. String to_string() const;
  63. bool operator==(Polygon const&) const = default;
  64. Gfx::WindingRule 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. }