EdgeStyleValue.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/CSSStyleValue.h>
  8. #include <LibWeb/CSS/Enums.h>
  9. #include <LibWeb/CSS/PercentageOr.h>
  10. namespace Web::CSS {
  11. class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValue> {
  12. public:
  13. static ValueComparingNonnullRefPtr<EdgeStyleValue> create(PositionEdge edge, LengthPercentage const& offset)
  14. {
  15. VERIFY(edge != PositionEdge::Center);
  16. return adopt_ref(*new (nothrow) EdgeStyleValue(edge, offset));
  17. }
  18. virtual ~EdgeStyleValue() override = default;
  19. // NOTE: `center` is converted to `left 50%` or `top 50%` in parsing, so is never returned here.
  20. PositionEdge edge() const { return m_properties.edge; }
  21. LengthPercentage const& offset() const { return m_properties.offset; }
  22. virtual String to_string() const override;
  23. bool properties_equal(EdgeStyleValue const& other) const { return m_properties == other.m_properties; }
  24. private:
  25. EdgeStyleValue(PositionEdge edge, LengthPercentage const& offset)
  26. : StyleValueWithDefaultOperators(Type::Edge)
  27. , m_properties { .edge = edge, .offset = offset }
  28. {
  29. }
  30. struct Properties {
  31. PositionEdge edge;
  32. LengthPercentage offset;
  33. bool operator==(Properties const&) const = default;
  34. } m_properties;
  35. };
  36. }