GridTrackSize.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GridTrackSize.h"
  7. #include <AK/String.h>
  8. #include <LibWeb/CSS/Length.h>
  9. #include <LibWeb/CSS/Percentage.h>
  10. #include <LibWeb/CSS/StyleValue.h>
  11. namespace Web::CSS {
  12. GridTrackSize::GridTrackSize(Length length)
  13. : m_type(Type::Length)
  14. , m_length(length)
  15. {
  16. }
  17. GridTrackSize::GridTrackSize(Percentage percentage)
  18. : m_type(Type::Percentage)
  19. , m_percentage(percentage)
  20. {
  21. }
  22. GridTrackSize::GridTrackSize(float flexible_length)
  23. : m_type(Type::FlexibleLength)
  24. , m_flexible_length(flexible_length)
  25. {
  26. }
  27. GridTrackSize GridTrackSize::make_auto()
  28. {
  29. return GridTrackSize(CSS::Length::make_auto());
  30. }
  31. String GridTrackSize::to_string() const
  32. {
  33. switch (m_type) {
  34. case Type::Length:
  35. return m_length.to_string();
  36. case Type::Percentage:
  37. return m_percentage.to_string();
  38. case Type::FlexibleLength:
  39. return String::formatted("{}fr", m_flexible_length);
  40. }
  41. VERIFY_NOT_REACHED();
  42. }
  43. }