AvailableSpace.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. VERIFY(isfinite(value.to_double()));
  12. return AvailableSize { Type::Definite, value };
  13. }
  14. AvailableSize AvailableSize::make_indefinite()
  15. {
  16. return AvailableSize { Type::Indefinite, INFINITY };
  17. }
  18. AvailableSize AvailableSize::make_min_content()
  19. {
  20. return AvailableSize { Type::MinContent, 0 };
  21. }
  22. AvailableSize AvailableSize::make_max_content()
  23. {
  24. return AvailableSize { Type::MaxContent, INFINITY };
  25. }
  26. DeprecatedString AvailableSize::to_deprecated_string() const
  27. {
  28. switch (m_type) {
  29. case Type::Definite:
  30. return DeprecatedString::formatted("definite({})", m_value);
  31. case Type::Indefinite:
  32. return "indefinite";
  33. case Type::MinContent:
  34. return "min-content";
  35. case Type::MaxContent:
  36. return "max-content";
  37. }
  38. VERIFY_NOT_REACHED();
  39. }
  40. DeprecatedString AvailableSpace::to_deprecated_string() const
  41. {
  42. return DeprecatedString::formatted("{} x {}", width, height);
  43. }
  44. AvailableSize::AvailableSize(Type type, CSSPixels value)
  45. : m_type(type)
  46. , m_value(value)
  47. {
  48. }
  49. }