2023-03-23 17:44:13 +00:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-23 17:44:13 +00:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2025-07-18 20:36:09 +02:00
|
|
|
#include "RepeatStyleStyleValue.h"
|
2023-03-23 17:44:13 +00:00
|
|
|
#include <AK/String.h>
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2025-07-18 20:36:09 +02:00
|
|
|
RepeatStyleStyleValue::RepeatStyleStyleValue(Repetition repeat_x, Repetition repeat_y)
|
|
|
|
: StyleValueWithDefaultOperators(Type::RepeatStyle)
|
2023-03-23 17:44:13 +00:00
|
|
|
, m_properties { .repeat_x = repeat_x, .repeat_y = repeat_y }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-07-18 20:36:09 +02:00
|
|
|
RepeatStyleStyleValue::~RepeatStyleStyleValue() = default;
|
2023-03-23 17:44:13 +00:00
|
|
|
|
2025-07-18 20:36:09 +02:00
|
|
|
String RepeatStyleStyleValue::to_string(SerializationMode) const
|
2023-03-23 17:44:13 +00:00
|
|
|
{
|
2024-11-28 15:48:07 +00:00
|
|
|
if (m_properties.repeat_x == m_properties.repeat_y)
|
|
|
|
return MUST(String::from_utf8(CSS::to_string(m_properties.repeat_x)));
|
|
|
|
|
2025-07-18 20:36:09 +02:00
|
|
|
if (m_properties.repeat_x == Repetition::Repeat && m_properties.repeat_y == Repetition::NoRepeat)
|
2024-11-28 15:48:07 +00:00
|
|
|
return "repeat-x"_string;
|
2025-07-18 20:36:09 +02:00
|
|
|
if (m_properties.repeat_x == Repetition::NoRepeat && m_properties.repeat_y == Repetition::Repeat)
|
2024-11-28 15:48:07 +00:00
|
|
|
return "repeat-y"_string;
|
|
|
|
|
2023-08-22 14:08:15 +01:00
|
|
|
return MUST(String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y)));
|
2023-03-23 17:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|