|
@@ -1,6 +1,7 @@
|
|
/*
|
|
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
|
|
|
+ * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
*
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
*/
|
|
@@ -273,6 +274,118 @@ String BoxShadowStyleValue::to_string() const
|
|
return String::formatted("{} {} {} {}", m_offset_x.to_string(), m_offset_y.to_string(), m_blur_radius.to_string(), m_color.to_string());
|
|
return String::formatted("{} {} {} {}", m_offset_x.to_string(), m_offset_y.to_string(), m_blur_radius.to_string(), m_color.to_string());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static float resolve_calc_value(CalculatedStyleValue::CalcValue const& calc_value, Layout::Node const& layout_node);
|
|
|
|
+static float resolve_calc_number_value(CalculatedStyleValue::CalcNumberValue const&);
|
|
|
|
+static float resolve_calc_product(NonnullOwnPtr<CalculatedStyleValue::CalcProduct> const& calc_product, Layout::Node const& layout_node);
|
|
|
|
+static float resolve_calc_sum(NonnullOwnPtr<CalculatedStyleValue::CalcSum> const& calc_sum, Layout::Node const& layout_node);
|
|
|
|
+static float resolve_calc_number_sum(NonnullOwnPtr<CalculatedStyleValue::CalcNumberSum> const&);
|
|
|
|
+static float resolve_calc_number_product(NonnullOwnPtr<CalculatedStyleValue::CalcNumberProduct> const&);
|
|
|
|
+
|
|
|
|
+Optional<Length> CalculatedStyleValue::resolve_length(Layout::Node const& layout_node) const
|
|
|
|
+{
|
|
|
|
+ auto length = resolve_calc_sum(m_expression, layout_node);
|
|
|
|
+ return Length::make_px(length);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_value(CalculatedStyleValue::CalcValue const& calc_value, Layout::Node const& layout_node)
|
|
|
|
+{
|
|
|
|
+ return calc_value.visit(
|
|
|
|
+ [](float value) { return value; },
|
|
|
|
+ [&](Length const& length) {
|
|
|
|
+ return length.resolved_or_zero(layout_node).to_px(layout_node);
|
|
|
|
+ },
|
|
|
|
+ [&](NonnullOwnPtr<CalculatedStyleValue::CalcSum> const& calc_sum) {
|
|
|
|
+ return resolve_calc_sum(calc_sum, layout_node);
|
|
|
|
+ },
|
|
|
|
+ [](auto&) {
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ return 0.0f;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_number_product(NonnullOwnPtr<CalculatedStyleValue::CalcNumberProduct> const& calc_number_product)
|
|
|
|
+{
|
|
|
|
+ auto value = resolve_calc_number_value(calc_number_product->first_calc_number_value);
|
|
|
|
+
|
|
|
|
+ for (auto& additional_number_value : calc_number_product->zero_or_more_additional_calc_number_values) {
|
|
|
|
+ auto additional_value = resolve_calc_number_value(additional_number_value.value);
|
|
|
|
+ if (additional_number_value.op == CalculatedStyleValue::CalcNumberProductPartWithOperator::Multiply)
|
|
|
|
+ value *= additional_value;
|
|
|
|
+ else if (additional_number_value.op == CalculatedStyleValue::CalcNumberProductPartWithOperator::Divide)
|
|
|
|
+ value /= additional_value;
|
|
|
|
+ else
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_number_sum(NonnullOwnPtr<CalculatedStyleValue::CalcNumberSum> const& calc_number_sum)
|
|
|
|
+{
|
|
|
|
+ auto value = resolve_calc_number_product(calc_number_sum->first_calc_number_product);
|
|
|
|
+
|
|
|
|
+ for (auto& additional_product : calc_number_sum->zero_or_more_additional_calc_number_products) {
|
|
|
|
+ auto additional_value = resolve_calc_number_product(additional_product.calc_number_product);
|
|
|
|
+ if (additional_product.op == CSS::CalculatedStyleValue::CalcNumberSumPartWithOperator::Add)
|
|
|
|
+ value += additional_value;
|
|
|
|
+ else if (additional_product.op == CSS::CalculatedStyleValue::CalcNumberSumPartWithOperator::Subtract)
|
|
|
|
+ value -= additional_value;
|
|
|
|
+ else
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_number_value(CalculatedStyleValue::CalcNumberValue const& number_value)
|
|
|
|
+{
|
|
|
|
+ return number_value.visit(
|
|
|
|
+ [](float number) { return number; },
|
|
|
|
+ [](NonnullOwnPtr<CalculatedStyleValue::CalcNumberSum> const& calc_number_sum) {
|
|
|
|
+ return resolve_calc_number_sum(calc_number_sum);
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_product(NonnullOwnPtr<CalculatedStyleValue::CalcProduct> const& calc_product, Layout::Node const& layout_node)
|
|
|
|
+{
|
|
|
|
+ auto value = resolve_calc_value(calc_product->first_calc_value, layout_node);
|
|
|
|
+
|
|
|
|
+ for (auto& additional_value : calc_product->zero_or_more_additional_calc_values) {
|
|
|
|
+ additional_value.value.visit(
|
|
|
|
+ [&](CalculatedStyleValue::CalcValue const& calc_value) {
|
|
|
|
+ if (additional_value.op != CalculatedStyleValue::CalcProductPartWithOperator::Multiply)
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ auto resolved_value = resolve_calc_value(calc_value, layout_node);
|
|
|
|
+ value *= resolved_value;
|
|
|
|
+ },
|
|
|
|
+ [&](CalculatedStyleValue::CalcNumberValue const& calc_number_value) {
|
|
|
|
+ if (additional_value.op != CalculatedStyleValue::CalcProductPartWithOperator::Divide)
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ auto resolved_calc_number_value = resolve_calc_number_value(calc_number_value);
|
|
|
|
+ value /= resolved_calc_number_value;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static float resolve_calc_sum(NonnullOwnPtr<CalculatedStyleValue::CalcSum> const& calc_sum, Layout::Node const& layout_node)
|
|
|
|
+{
|
|
|
|
+ auto value = resolve_calc_product(calc_sum->first_calc_product, layout_node);
|
|
|
|
+
|
|
|
|
+ for (auto& additional_product : calc_sum->zero_or_more_additional_calc_products) {
|
|
|
|
+ auto additional_value = resolve_calc_product(additional_product.calc_product, layout_node);
|
|
|
|
+ if (additional_product.op == CalculatedStyleValue::CalcSumPartWithOperator::Operation::Add)
|
|
|
|
+ value += additional_value;
|
|
|
|
+ else if (additional_product.op == CalculatedStyleValue::CalcSumPartWithOperator::Operation::Subtract)
|
|
|
|
+ value -= additional_value;
|
|
|
|
+ else
|
|
|
|
+ VERIFY_NOT_REACHED();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
|
|
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
|
|
String ColorStyleValue::to_string() const
|
|
String ColorStyleValue::to_string() const
|
|
{
|
|
{
|