GridTrackSize.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/Length.h>
  8. #include <LibWeb/CSS/Percentage.h>
  9. namespace Web::CSS {
  10. class GridTrackSize {
  11. public:
  12. enum class Type {
  13. Length,
  14. Percentage,
  15. FlexibleLength,
  16. // TODO: MinMax
  17. // TODO: Repeat
  18. // TODO: Max-Content
  19. };
  20. GridTrackSize(Length);
  21. GridTrackSize(Percentage);
  22. GridTrackSize(float);
  23. ~GridTrackSize();
  24. static GridTrackSize make_auto();
  25. Type type() const { return m_type; }
  26. bool is_length() const { return m_type == Type::Length; }
  27. bool is_percentage() const { return m_type == Type::Percentage; }
  28. bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
  29. Length length() const;
  30. Percentage percentage() const { return m_percentage; }
  31. float flexible_length() const { return m_flexible_length; }
  32. // https://drafts.csswg.org/css-grid/#layout-algorithm
  33. // Intrinsic sizing function - min-content, max-content, auto, fit-content()
  34. // FIXME: Add missing properties once implemented.
  35. bool is_intrinsic_track_sizing() const
  36. {
  37. return (m_type == Type::Length && m_length.is_auto());
  38. }
  39. String to_string() const;
  40. bool operator==(GridTrackSize const& other) const
  41. {
  42. return m_type == other.type()
  43. && m_length == other.length()
  44. && m_percentage == other.percentage()
  45. && m_flexible_length == other.flexible_length();
  46. }
  47. private:
  48. Type m_type;
  49. // Length includes a RefPtr<CalculatedStyleValue> member, but we can't include the header StyleValue.h as it includes
  50. // this file already. To break the cyclic dependency, we must initialize m_length in the constructor.
  51. Length m_length;
  52. Percentage m_percentage { Percentage(0) };
  53. float m_flexible_length { 0 };
  54. };
  55. }