mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibWeb: Remove reference_for_percent parameter from Length::resolved()
Despite looking like it was still needed, it was only used for passing to other calls to Length::resolved() recursively. This makes the various `foo.resolved().resolved()` calls a lot less awkward. (Though, still quite awkward.) I think we'd need to separate calculated lengths out to properly tidy these calls up, but one yak at a time. :^)
This commit is contained in:
parent
cff44831a8
commit
bfcbab0dcf
11 changed files with 133 additions and 132 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -49,25 +50,25 @@ Length Length::percentage_of(Percentage const& percentage) const
|
|||
return Length { percentage.as_fraction() * raw_value(), m_type };
|
||||
}
|
||||
|
||||
Length Length::resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const
|
||||
Length Length::resolved(Length const& fallback_for_undefined, Layout::Node const& layout_node) const
|
||||
{
|
||||
if (is_undefined())
|
||||
return fallback_for_undefined;
|
||||
if (is_calculated())
|
||||
return Length(resolve_calculated_value(layout_node, reference_for_percent), Type::Px);
|
||||
return Length(resolve_calculated_value(layout_node), Type::Px);
|
||||
if (is_relative())
|
||||
return make_px(to_px(layout_node));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Length Length::resolved_or_auto(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
Length Length::resolved_or_auto(Layout::Node const& layout_node) const
|
||||
{
|
||||
return resolved(make_auto(), layout_node, reference_for_percent);
|
||||
return resolved(make_auto(), layout_node);
|
||||
}
|
||||
|
||||
Length Length::resolved_or_zero(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
Length Length::resolved_or_zero(Layout::Node const& layout_node) const
|
||||
{
|
||||
return resolved(make_px(0), layout_node, reference_for_percent);
|
||||
return resolved(make_px(0), layout_node);
|
||||
}
|
||||
|
||||
void Length::set_calculated_style(CalculatedStyleValue* value)
|
||||
|
@ -111,33 +112,33 @@ float Length::to_px(Layout::Node const& layout_node) const
|
|||
return to_px(viewport_rect, layout_node.font().metrics('M'), root_element->layout_node()->font().presentation_size());
|
||||
}
|
||||
|
||||
static float resolve_calc_value(CalculatedStyleValue::CalcValue const&, const Layout::Node& layout_node, float reference_for_percent);
|
||||
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&, const Layout::Node& layout_node, float reference_for_percent);
|
||||
static float resolve_calc_sum(NonnullOwnPtr<CalculatedStyleValue::CalcSum> const&, const Layout::Node& layout_node, float reference_for_percent);
|
||||
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&);
|
||||
|
||||
float Length::resolve_calculated_value(const Layout::Node& layout_node, float reference_for_percent) const
|
||||
float Length::resolve_calculated_value(Layout::Node const& layout_node) const
|
||||
{
|
||||
if (!m_calculated_style)
|
||||
return 0.0f;
|
||||
|
||||
auto& expression = m_calculated_style->expression();
|
||||
|
||||
auto length = resolve_calc_sum(expression, layout_node, reference_for_percent);
|
||||
auto length = resolve_calc_sum(expression, layout_node);
|
||||
return length;
|
||||
};
|
||||
|
||||
static float resolve_calc_value(CalculatedStyleValue::CalcValue const& calc_value, const Layout::Node& layout_node, float reference_for_percent)
|
||||
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, reference_for_percent).to_px(layout_node);
|
||||
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, reference_for_percent);
|
||||
return resolve_calc_sum(calc_sum, layout_node);
|
||||
},
|
||||
[](auto&) {
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -188,16 +189,16 @@ static float resolve_calc_number_value(CalculatedStyleValue::CalcNumberValue con
|
|||
});
|
||||
}
|
||||
|
||||
static float resolve_calc_product(NonnullOwnPtr<CalculatedStyleValue::CalcProduct> const& calc_product, const Layout::Node& layout_node, float reference_for_percent)
|
||||
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, reference_for_percent);
|
||||
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, reference_for_percent);
|
||||
auto resolved_value = resolve_calc_value(calc_value, layout_node);
|
||||
value *= resolved_value;
|
||||
},
|
||||
[&](CalculatedStyleValue::CalcNumberValue const& calc_number_value) {
|
||||
|
@ -211,12 +212,12 @@ static float resolve_calc_product(NonnullOwnPtr<CalculatedStyleValue::CalcProduc
|
|||
return value;
|
||||
}
|
||||
|
||||
static float resolve_calc_sum(NonnullOwnPtr<CalculatedStyleValue::CalcSum> const& calc_sum, const Layout::Node& layout_node, float reference_for_percent)
|
||||
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, reference_for_percent);
|
||||
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, reference_for_percent);
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue