2023-04-02 18:56:45 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "EdgeStyleValue.h"
|
2025-10-23 03:33:58 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
|
|
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
2023-04-02 18:56:45 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2024-11-29 08:44:14 -03:00
|
|
|
String EdgeStyleValue::to_string(SerializationMode mode) const
|
2023-04-02 18:56:45 -03:00
|
|
|
{
|
2025-05-16 15:20:24 -03:00
|
|
|
if (mode == SerializationMode::ResolvedValue) {
|
2025-04-11 01:56:50 -03:00
|
|
|
// FIXME: Figure out how to get the proper calculation context here
|
|
|
|
|
CalculationContext context {};
|
2025-10-23 03:33:58 -03:00
|
|
|
return resolved_value(context)->offset()->to_string(mode);
|
2024-11-29 08:44:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder builder;
|
|
|
|
|
|
|
|
|
|
if (m_properties.edge.has_value())
|
|
|
|
|
builder.append(CSS::to_string(m_properties.edge.value()));
|
|
|
|
|
|
2025-10-23 03:33:58 -03:00
|
|
|
if (m_properties.edge.has_value() && m_properties.offset)
|
2024-11-29 08:44:14 -03:00
|
|
|
builder.append(' ');
|
|
|
|
|
|
2025-10-23 03:33:58 -03:00
|
|
|
if (m_properties.offset)
|
2025-08-03 00:37:42 -03:00
|
|
|
builder.append(m_properties.offset->to_string(mode));
|
2024-11-29 08:44:14 -03:00
|
|
|
|
|
|
|
|
return builder.to_string_without_validation();
|
2023-04-02 18:56:45 -03:00
|
|
|
}
|
|
|
|
|
|
2025-04-11 01:56:50 -03:00
|
|
|
ValueComparingNonnullRefPtr<EdgeStyleValue const> EdgeStyleValue::resolved_value(CalculationContext context) const
|
|
|
|
|
{
|
|
|
|
|
if (edge() == PositionEdge::Right || edge() == PositionEdge::Bottom) {
|
2025-10-23 03:33:58 -03:00
|
|
|
if (offset()->is_percentage()) {
|
|
|
|
|
auto flipped_percentage = 100 - offset()->as_percentage().percentage().value();
|
|
|
|
|
return create({}, PercentageStyleValue::create(Percentage(flipped_percentage)));
|
2025-04-11 01:56:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector<NonnullRefPtr<CalculationNode const>> sum_parts;
|
|
|
|
|
sum_parts.append(NumericCalculationNode::create(Percentage(100), context));
|
2025-10-23 03:33:58 -03:00
|
|
|
if (offset()->is_length()) {
|
|
|
|
|
sum_parts.append(NegateCalculationNode::create(NumericCalculationNode::create(offset()->as_length().length(), context)));
|
2025-04-11 01:56:50 -03:00
|
|
|
} else {
|
|
|
|
|
// FIXME: Flip calculated offsets (convert CalculatedStyleValue to CalculationNode, then negate and append)
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-08-15 08:55:58 -03:00
|
|
|
auto flipped_absolute = CalculatedStyleValue::create(SumCalculationNode::create(move(sum_parts)), NumericType(NumericType::BaseType::Length, 1), context);
|
2025-04-11 01:56:50 -03:00
|
|
|
return create({}, flipped_absolute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-02 18:56:45 -03:00
|
|
|
}
|