BackgroundRepeatStyleValue.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include "BackgroundRepeatStyleValue.h"
  10. #include <AK/String.h>
  11. namespace Web::CSS {
  12. BackgroundRepeatStyleValue::BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y)
  13. : StyleValueWithDefaultOperators(Type::BackgroundRepeat)
  14. , m_properties { .repeat_x = repeat_x, .repeat_y = repeat_y }
  15. {
  16. }
  17. BackgroundRepeatStyleValue::~BackgroundRepeatStyleValue() = default;
  18. String BackgroundRepeatStyleValue::to_string(SerializationMode) const
  19. {
  20. if (m_properties.repeat_x == m_properties.repeat_y)
  21. return MUST(String::from_utf8(CSS::to_string(m_properties.repeat_x)));
  22. if (m_properties.repeat_x == Repeat::Repeat && m_properties.repeat_y == Repeat::NoRepeat)
  23. return "repeat-x"_string;
  24. if (m_properties.repeat_x == Repeat::NoRepeat && m_properties.repeat_y == Repeat::Repeat)
  25. return "repeat-y"_string;
  26. return MUST(String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y)));
  27. }
  28. }