GridTrackPlacement.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. namespace Web::CSS {
  9. class GridTrackPlacement {
  10. public:
  11. enum class Type {
  12. Span,
  13. Position,
  14. Auto
  15. };
  16. GridTrackPlacement(String line_name, int span_count_or_position, bool has_span = false);
  17. GridTrackPlacement(int span_count_or_position, bool has_span = false);
  18. GridTrackPlacement(String line_name, bool has_span = false);
  19. GridTrackPlacement();
  20. static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
  21. bool is_span() const { return m_type == Type::Span; }
  22. bool is_position() const { return m_type == Type::Position; }
  23. bool is_auto() const { return m_type == Type::Auto; }
  24. bool is_auto_positioned() const { return m_type == Type::Auto || (m_type == Type::Span && !has_line_name()); }
  25. bool has_line_name() const { return !m_line_name.is_empty(); }
  26. int raw_value() const { return m_span_count_or_position; }
  27. Type type() const { return m_type; }
  28. String line_name() const { return m_line_name; }
  29. ErrorOr<String> to_string() const;
  30. bool operator==(GridTrackPlacement const& other) const
  31. {
  32. return m_type == other.type() && m_span_count_or_position == other.raw_value();
  33. }
  34. private:
  35. Type m_type;
  36. int m_span_count_or_position { 0 };
  37. String m_line_name;
  38. };
  39. }