PositionStyleValue.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibWeb/CSS/Enums.h>
  11. #include <LibWeb/CSS/Percentage.h>
  12. #include <LibWeb/CSS/StyleValue.h>
  13. namespace Web::CSS {
  14. class PositionStyleValue final : public StyleValueWithDefaultOperators<PositionStyleValue> {
  15. public:
  16. static ValueComparingNonnullRefPtr<PositionStyleValue> create(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y)
  17. {
  18. return adopt_ref(*new PositionStyleValue(edge_x, offset_x, edge_y, offset_y));
  19. }
  20. virtual ~PositionStyleValue() override = default;
  21. PositionEdge edge_x() const { return m_properties.edge_x; }
  22. LengthPercentage const& offset_x() const { return m_properties.offset_x; }
  23. PositionEdge edge_y() const { return m_properties.edge_y; }
  24. LengthPercentage const& offset_y() const { return m_properties.offset_y; }
  25. virtual ErrorOr<String> to_string() const override;
  26. bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; }
  27. private:
  28. PositionStyleValue(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y)
  29. : StyleValueWithDefaultOperators(Type::Position)
  30. , m_properties { .edge_x = edge_x, .offset_x = offset_x, .edge_y = edge_y, .offset_y = offset_y }
  31. {
  32. }
  33. struct Properties {
  34. PositionEdge edge_x;
  35. LengthPercentage offset_x;
  36. PositionEdge edge_y;
  37. LengthPercentage offset_y;
  38. bool operator==(Properties const&) const = default;
  39. } m_properties;
  40. };
  41. }