2023-04-02 22:56:45 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "EdgeStyleValue.h"
|
2025-10-23 19:33:58 +13:00
|
|
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
2025-12-24 15:54:27 +13:00
|
|
|
#include <LibWeb/CSS/ValueType.h>
|
2023-04-02 22:56:45 +01:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2025-12-24 23:05:32 +13:00
|
|
|
bool EdgeStyleValue::is_center(SerializationMode mode) const
|
2023-04-02 22:56:45 +01:00
|
|
|
{
|
2025-12-24 15:54:27 +13:00
|
|
|
if (m_properties.edge == PositionEdge::Center)
|
|
|
|
|
return true;
|
2024-11-29 22:44:14 +11:00
|
|
|
|
2025-12-24 23:05:32 +13:00
|
|
|
if (m_properties.offset && m_properties.offset->to_string(mode) == "50%"sv)
|
2025-12-24 15:54:27 +13:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String EdgeStyleValue::to_string(SerializationMode mode) const
|
|
|
|
|
{
|
2024-11-29 22:44:14 +11:00
|
|
|
StringBuilder builder;
|
|
|
|
|
|
|
|
|
|
if (m_properties.edge.has_value())
|
|
|
|
|
builder.append(CSS::to_string(m_properties.edge.value()));
|
|
|
|
|
|
2025-10-23 19:33:58 +13:00
|
|
|
if (m_properties.edge.has_value() && m_properties.offset)
|
2024-11-29 22:44:14 +11:00
|
|
|
builder.append(' ');
|
|
|
|
|
|
2025-10-23 19:33:58 +13:00
|
|
|
if (m_properties.offset)
|
2025-08-03 15:37:42 +12:00
|
|
|
builder.append(m_properties.offset->to_string(mode));
|
2024-11-29 22:44:14 +11:00
|
|
|
|
|
|
|
|
return builder.to_string_without_validation();
|
2023-04-02 22:56:45 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-04 01:07:21 +13:00
|
|
|
ValueComparingNonnullRefPtr<EdgeStyleValue const> EdgeStyleValue::with_resolved_keywords() const
|
2025-04-11 05:56:50 +01:00
|
|
|
{
|
2025-12-24 15:54:27 +13:00
|
|
|
if (m_properties.edge == PositionEdge::Center)
|
|
|
|
|
return EdgeStyleValue::create({}, PercentageStyleValue::create(Percentage(50)));
|
|
|
|
|
|
|
|
|
|
CalculationContext calculation_context {
|
|
|
|
|
.percentages_resolve_as = ValueType::Length,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (m_properties.edge == PositionEdge::Right || m_properties.edge == PositionEdge::Bottom) {
|
|
|
|
|
if (!m_properties.offset)
|
|
|
|
|
return EdgeStyleValue::create({}, PercentageStyleValue::create(Percentage(100)));
|
|
|
|
|
|
2026-01-04 01:07:21 +13:00
|
|
|
auto negated_offset = NegateCalculationNode::create(CalculationNode::from_style_value(*m_properties.offset, calculation_context));
|
|
|
|
|
|
|
|
|
|
auto flipped_offset = simplify_a_calculation_tree(
|
|
|
|
|
SumCalculationNode::create({ NumericCalculationNode::create(Percentage { 100 }, calculation_context), negated_offset }),
|
|
|
|
|
calculation_context,
|
|
|
|
|
{});
|
2025-12-24 15:54:27 +13:00
|
|
|
|
2026-01-04 01:07:21 +13:00
|
|
|
auto flipped_percentage_style_value = CalculatedStyleValue::create(flipped_offset, NumericType(NumericType::BaseType::Length, 1), calculation_context);
|
2025-12-24 15:54:27 +13:00
|
|
|
|
2026-01-04 01:07:21 +13:00
|
|
|
return EdgeStyleValue::create({}, flipped_percentage_style_value);
|
2025-04-11 05:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-24 15:54:27 +13:00
|
|
|
if (!m_properties.offset)
|
|
|
|
|
return EdgeStyleValue::create({}, PercentageStyleValue::create(Percentage(0)));
|
|
|
|
|
|
2026-01-04 01:07:21 +13:00
|
|
|
return EdgeStyleValue::create({}, m_properties.offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> EdgeStyleValue::absolutized(ComputationContext const& computation_context) const
|
|
|
|
|
{
|
|
|
|
|
return EdgeStyleValue::create({}, with_resolved_keywords()->offset()->absolutized(computation_context));
|
2025-04-11 05:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-02 22:56:45 +01:00
|
|
|
}
|