|
@@ -27,6 +27,12 @@ StyleValue::~StyleValue()
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+AngleStyleValue const& StyleValue::as_angle() const
|
|
|
|
+{
|
|
|
|
+ VERIFY(is_angle());
|
|
|
|
+ return static_cast<AngleStyleValue const&>(*this);
|
|
|
|
+}
|
|
|
|
+
|
|
BackgroundStyleValue const& StyleValue::as_background() const
|
|
BackgroundStyleValue const& StyleValue::as_background() const
|
|
{
|
|
{
|
|
VERIFY(is_background());
|
|
VERIFY(is_background());
|
|
@@ -309,6 +315,24 @@ void CalculatedStyleValue::CalculationResult::add_or_subtract_internal(SumOperat
|
|
};
|
|
};
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ [&](Angle const& angle) {
|
|
|
|
+ auto this_degrees = angle.to_degrees();
|
|
|
|
+ if (other.m_value.has<Angle>()) {
|
|
|
|
+ auto other_degrees = other.m_value.get<Angle>().to_degrees();
|
|
|
|
+ if (op == SumOperation::Add)
|
|
|
|
+ m_value = Angle::make_degrees(this_degrees + other_degrees);
|
|
|
|
+ else
|
|
|
|
+ m_value = Angle::make_degrees(this_degrees - other_degrees);
|
|
|
|
+ } else {
|
|
|
|
+ VERIFY(percentage_basis.has<Angle>());
|
|
|
|
+
|
|
|
|
+ auto other_degrees = percentage_basis.get<Angle>().percentage_of(other.m_value.get<Percentage>()).to_degrees();
|
|
|
|
+ if (op == SumOperation::Add)
|
|
|
|
+ m_value = Angle::make_degrees(this_degrees + other_degrees);
|
|
|
|
+ else
|
|
|
|
+ m_value = Angle::make_degrees(this_degrees - other_degrees);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
[&](Length const& length) {
|
|
[&](Length const& length) {
|
|
auto this_px = length.to_px(*layout_node);
|
|
auto this_px = length.to_px(*layout_node);
|
|
if (other.m_value.has<Length>()) {
|
|
if (other.m_value.has<Length>()) {
|
|
@@ -369,6 +393,9 @@ void CalculatedStyleValue::CalculationResult::multiply_by(CalculationResult cons
|
|
*this = new_value;
|
|
*this = new_value;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ [&](Angle const& angle) {
|
|
|
|
+ m_value = Angle::make_degrees(angle.to_degrees() * other.m_value.get<Number>().value);
|
|
|
|
+ },
|
|
[&](Length const& length) {
|
|
[&](Length const& length) {
|
|
VERIFY(layout_node);
|
|
VERIFY(layout_node);
|
|
m_value = Length::make_px(length.to_px(*layout_node) * other.m_value.get<Number>().value);
|
|
m_value = Length::make_px(length.to_px(*layout_node) * other.m_value.get<Number>().value);
|
|
@@ -393,6 +420,9 @@ void CalculatedStyleValue::CalculationResult::divide_by(CalculationResult const&
|
|
.value = number.value / denominator
|
|
.value = number.value / denominator
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
+ [&](Angle const& angle) {
|
|
|
|
+ m_value = Angle::make_degrees(angle.to_degrees() / denominator);
|
|
|
|
+ },
|
|
[&](Length const& length) {
|
|
[&](Length const& length) {
|
|
VERIFY(layout_node);
|
|
VERIFY(layout_node);
|
|
m_value = Length::make_px(length.to_px(*layout_node) / denominator);
|
|
m_value = Length::make_px(length.to_px(*layout_node) / denominator);
|
|
@@ -418,9 +448,8 @@ String CalculatedStyleValue::CalcValue::to_string() const
|
|
{
|
|
{
|
|
return value.visit(
|
|
return value.visit(
|
|
[](Number const& number) { return String::number(number.value); },
|
|
[](Number const& number) { return String::number(number.value); },
|
|
- [](Length const& length) { return length.to_string(); },
|
|
|
|
- [](Percentage const& percentage) { return percentage.to_string(); },
|
|
|
|
- [](NonnullOwnPtr<CalcSum> const& sum) { return String::formatted("({})", sum->to_string()); });
|
|
|
|
|
|
+ [](NonnullOwnPtr<CalcSum> const& sum) { return String::formatted("({})", sum->to_string()); },
|
|
|
|
+ [](auto const& v) { return v.to_string(); });
|
|
}
|
|
}
|
|
|
|
|
|
String CalculatedStyleValue::CalcSum::to_string() const
|
|
String CalculatedStyleValue::CalcSum::to_string() const
|
|
@@ -482,35 +511,53 @@ String CalculatedStyleValue::CalcNumberSumPartWithOperator::to_string() const
|
|
return String::formatted(" {} {}", op == SumOperation::Add ? "+"sv : "-"sv, value->to_string());
|
|
return String::formatted(" {} {}", op == SumOperation::Add ? "+"sv : "-"sv, value->to_string());
|
|
}
|
|
}
|
|
|
|
|
|
-Optional<Length> CalculatedStyleValue::resolve_length(Layout::Node const& layout_node) const
|
|
|
|
|
|
+Optional<Angle> CalculatedStyleValue::resolve_angle() const
|
|
{
|
|
{
|
|
- auto result = m_expression->resolve(&layout_node, {});
|
|
|
|
|
|
+ auto result = m_expression->resolve(nullptr, {});
|
|
|
|
+
|
|
|
|
+ if (result.value().has<Angle>())
|
|
|
|
+ return result.value().get<Angle>();
|
|
|
|
+ return {};
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Optional<AnglePercentage> CalculatedStyleValue::resolve_angle_percentage(Angle const& percentage_basis) const
|
|
|
|
+{
|
|
|
|
+ auto result = m_expression->resolve(nullptr, percentage_basis);
|
|
|
|
|
|
return result.value().visit(
|
|
return result.value().visit(
|
|
- [&](Number) -> Optional<Length> {
|
|
|
|
- return {};
|
|
|
|
|
|
+ [&](Angle const& angle) -> Optional<AnglePercentage> {
|
|
|
|
+ return angle;
|
|
},
|
|
},
|
|
- [&](Length const& length) -> Optional<Length> {
|
|
|
|
- return length;
|
|
|
|
|
|
+ [&](Percentage const& percentage) -> Optional<AnglePercentage> {
|
|
|
|
+ return percentage;
|
|
},
|
|
},
|
|
- [&](Percentage const&) -> Optional<Length> {
|
|
|
|
|
|
+ [&](auto const&) -> Optional<AnglePercentage> {
|
|
return {};
|
|
return {};
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Optional<Length> CalculatedStyleValue::resolve_length(Layout::Node const& layout_node) const
|
|
|
|
+{
|
|
|
|
+ auto result = m_expression->resolve(&layout_node, {});
|
|
|
|
+
|
|
|
|
+ if (result.value().has<Length>())
|
|
|
|
+ return result.value().get<Length>();
|
|
|
|
+ return {};
|
|
|
|
+}
|
|
|
|
+
|
|
Optional<LengthPercentage> CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, Length const& percentage_basis) const
|
|
Optional<LengthPercentage> CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, Length const& percentage_basis) const
|
|
{
|
|
{
|
|
auto result = m_expression->resolve(&layout_node, percentage_basis);
|
|
auto result = m_expression->resolve(&layout_node, percentage_basis);
|
|
|
|
|
|
return result.value().visit(
|
|
return result.value().visit(
|
|
- [&](Number) -> Optional<LengthPercentage> {
|
|
|
|
- return {};
|
|
|
|
- },
|
|
|
|
[&](Length const& length) -> Optional<LengthPercentage> {
|
|
[&](Length const& length) -> Optional<LengthPercentage> {
|
|
return length;
|
|
return length;
|
|
},
|
|
},
|
|
[&](Percentage const& percentage) -> Optional<LengthPercentage> {
|
|
[&](Percentage const& percentage) -> Optional<LengthPercentage> {
|
|
return percentage;
|
|
return percentage;
|
|
|
|
+ },
|
|
|
|
+ [&](auto const&) -> Optional<LengthPercentage> {
|
|
|
|
+ return {};
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -697,6 +744,7 @@ Optional<CalculatedStyleValue::ResolvedType> CalculatedStyleValue::CalcValue::re
|
|
[](Number const& number) -> Optional<CalculatedStyleValue::ResolvedType> {
|
|
[](Number const& number) -> Optional<CalculatedStyleValue::ResolvedType> {
|
|
return { number.is_integer ? ResolvedType::Integer : ResolvedType::Number };
|
|
return { number.is_integer ? ResolvedType::Integer : ResolvedType::Number };
|
|
},
|
|
},
|
|
|
|
+ [](Angle const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Angle }; },
|
|
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
|
|
[](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
|
|
[](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
|
|
[](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
|
|
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
|
|
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
|
|
@@ -725,17 +773,11 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberValue::r
|
|
CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve(Layout::Node const* layout_node, PercentageBasis const& percentage_basis) const
|
|
CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve(Layout::Node const* layout_node, PercentageBasis const& percentage_basis) const
|
|
{
|
|
{
|
|
return value.visit(
|
|
return value.visit(
|
|
- [&](Number const& number) -> CalculatedStyleValue::CalculationResult {
|
|
|
|
- return CalculatedStyleValue::CalculationResult { number };
|
|
|
|
- },
|
|
|
|
- [&](Length const& length) -> CalculatedStyleValue::CalculationResult {
|
|
|
|
- return CalculatedStyleValue::CalculationResult { length };
|
|
|
|
- },
|
|
|
|
- [&](Percentage const& percentage) -> CalculatedStyleValue::CalculationResult {
|
|
|
|
- return CalculatedStyleValue::CalculationResult { percentage };
|
|
|
|
- },
|
|
|
|
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
|
|
[&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
|
|
return sum->resolve(layout_node, percentage_basis);
|
|
return sum->resolve(layout_node, percentage_basis);
|
|
|
|
+ },
|
|
|
|
+ [&](auto const& v) -> CalculatedStyleValue::CalculationResult {
|
|
|
|
+ return CalculatedStyleValue::CalculationResult { v };
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|