GridTrackSize.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. static GridTrackSize make_auto();
  24. Type type() const { return m_type; }
  25. bool is_length() const { return m_type == Type::Length; }
  26. bool is_percentage() const { return m_type == Type::Percentage; }
  27. bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
  28. Length length() const { return m_length; }
  29. Percentage percentage() const { return m_percentage; }
  30. float flexible_length() const { return m_flexible_length; }
  31. // https://drafts.csswg.org/css-grid/#layout-algorithm
  32. // Intrinsic sizing function - min-content, max-content, auto, fit-content()
  33. // FIXME: Add missing properties once implemented.
  34. bool is_intrinsic_track_sizing() const
  35. {
  36. return (m_type == Type::Length && m_length.is_auto());
  37. }
  38. String to_string() const;
  39. bool operator==(GridTrackSize const& other) const
  40. {
  41. return m_type == other.type()
  42. && m_length == other.length()
  43. && m_percentage == other.percentage()
  44. && m_flexible_length == other.flexible_length();
  45. }
  46. private:
  47. Type m_type;
  48. Length m_length { Length::make_px(0) };
  49. Percentage m_percentage { Percentage(0) };
  50. float m_flexible_length { 0 };
  51. };
  52. }