Display.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/CSS/Display.h>
  7. namespace Web::CSS {
  8. String Display::to_string() const
  9. {
  10. StringBuilder builder;
  11. switch (m_type) {
  12. case Type::OutsideAndInside:
  13. // NOTE: Following the precedence rules of “most backwards-compatible, then shortest”,
  14. // serialization of equivalent display values uses the “Short display” column.
  15. if (*this == Display::from_short(Display::Short::Block))
  16. return "block"_string;
  17. if (*this == Display::from_short(Display::Short::FlowRoot))
  18. return "flow-root"_string;
  19. if (*this == Display::from_short(Display::Short::Inline))
  20. return "inline"_string;
  21. if (*this == Display::from_short(Display::Short::InlineBlock))
  22. return "inline-block"_string;
  23. if (*this == Display::from_short(Display::Short::RunIn))
  24. return "run-in"_string;
  25. if (*this == Display::from_short(Display::Short::ListItem))
  26. return "list-item"_string;
  27. if (*this == Display::from_short(Display::Short::Flex))
  28. return "flex"_string;
  29. if (*this == Display::from_short(Display::Short::InlineFlex))
  30. return "inline-flex"_string;
  31. if (*this == Display::from_short(Display::Short::Grid))
  32. return "grid"_string;
  33. if (*this == Display::from_short(Display::Short::InlineGrid))
  34. return "inline-grid"_string;
  35. if (*this == Display::from_short(Display::Short::Ruby))
  36. return "ruby"_string;
  37. if (*this == Display::from_short(Display::Short::Table))
  38. return "table"_string;
  39. if (*this == Display::from_short(Display::Short::InlineTable))
  40. return "inline-table"_string;
  41. builder.append(CSS::to_string(m_value.outside_inside.outside));
  42. builder.append(' ');
  43. builder.append(CSS::to_string(m_value.outside_inside.inside));
  44. if (m_value.outside_inside.list_item == ListItem::Yes)
  45. builder.append(" list-item"sv);
  46. break;
  47. case Type::Internal:
  48. builder.append(CSS::to_string(m_value.internal));
  49. break;
  50. case Type::Box:
  51. builder.append(CSS::to_string(m_value.box));
  52. break;
  53. };
  54. return MUST(builder.to_string());
  55. }
  56. }