AvailableSpace.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Layout/AvailableSpace.h>
  7. #include <math.h>
  8. namespace Web::Layout {
  9. AvailableSize AvailableSize::make_definite(CSSPixels value)
  10. {
  11. return AvailableSize { Type::Definite, value };
  12. }
  13. AvailableSize AvailableSize::make_indefinite()
  14. {
  15. return AvailableSize { Type::Indefinite, INFINITY };
  16. }
  17. AvailableSize AvailableSize::make_min_content()
  18. {
  19. return AvailableSize { Type::MinContent, 0 };
  20. }
  21. AvailableSize AvailableSize::make_max_content()
  22. {
  23. return AvailableSize { Type::MaxContent, INFINITY };
  24. }
  25. DeprecatedString AvailableSize::to_deprecated_string() const
  26. {
  27. switch (m_type) {
  28. case Type::Definite:
  29. return DeprecatedString::formatted("definite({})", m_value);
  30. case Type::Indefinite:
  31. return "indefinite";
  32. case Type::MinContent:
  33. return "min-content";
  34. case Type::MaxContent:
  35. return "max-content";
  36. }
  37. VERIFY_NOT_REACHED();
  38. }
  39. DeprecatedString AvailableSpace::to_deprecated_string() const
  40. {
  41. return DeprecatedString::formatted("{} x {}", width, height);
  42. }
  43. AvailableSize::AvailableSize(Type type, CSSPixels value)
  44. : m_type(type)
  45. , m_value(value)
  46. {
  47. }
  48. }