From 6969d1eba32459e10e1522d5b2547b8b17a0bf6e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 17 Dec 2024 14:00:41 +0000 Subject: [PATCH] LibWeb/CSS: Parse calc() as intermediate types instead of UnparsedCN Previously we created a tree of CalculationNodes with dummy UnparsedCalculationNode children, and then swapped those with the real children. This matched the spec closely but had the unfortunate downside that CalculationNodes couldn't be immutable, and couldn't know their properties at construct-time. UnparsedCalculationNode is also a footgun, as if it gets left in the tree accidentally we would VERIFY(). So instead, let's parse the calc() tree into an intermediate format, and then convert each node in that tree, depth-first, into its corresponding CalculationNode. This means each CalculationNode knows what its children are when it is constructed, and they never change. Apart from deleting UnparsedCalculationNode, we can also get rid of the for_each_child_node() method that was only used by this "replace the children" code. --- Libraries/LibWeb/CSS/Parser/Parser.cpp | 280 +++++++++--------- Libraries/LibWeb/CSS/Parser/Parser.h | 25 ++ .../LibWeb/CSS/StyleValues/CSSMathValue.cpp | 170 ----------- .../LibWeb/CSS/StyleValues/CSSMathValue.h | 27 -- 4 files changed, 166 insertions(+), 336 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 0ac42abb0a0..9fd9f8b31d2 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -9013,39 +9012,6 @@ Optional Parser::parse_css_value_for_properties(Readon return OptionalNone {}; } -class UnparsedCalculationNode final : public CalculationNode { -public: - static NonnullOwnPtr create(ComponentValue component_value) - { - return adopt_own(*new (nothrow) UnparsedCalculationNode(move(component_value))); - } - virtual ~UnparsedCalculationNode() = default; - - ComponentValue& component_value() { return m_component_value; } - - virtual String to_string() const override { VERIFY_NOT_REACHED(); } - virtual Optional resolved_type() const override { VERIFY_NOT_REACHED(); } - virtual Optional determine_type(Web::CSS::PropertyID) const override { VERIFY_NOT_REACHED(); } - virtual bool contains_percentage() const override { VERIFY_NOT_REACHED(); } - virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override { VERIFY_NOT_REACHED(); } - virtual void for_each_child_node(AK::Function&)> const&) override { } - - virtual void dump(StringBuilder& builder, int indent) const override - { - builder.appendff("{: >{}}UNPARSED({})\n", "", indent, m_component_value.to_debug_string()); - } - virtual bool equals(CalculationNode const&) const override { return false; } - -private: - UnparsedCalculationNode(ComponentValue component_value) - : CalculationNode(Type::Unparsed) - , m_component_value(move(component_value)) - { - } - - ComponentValue m_component_value; -}; - // https://html.spec.whatwg.org/multipage/images.html#parsing-a-sizes-attribute LengthOrCalculated Parser::Parser::parse_as_sizes_attribute(DOM::Element const& element, HTML::HTMLImageElement const* img) { @@ -9148,26 +9114,130 @@ LengthOrCalculated Parser::Parser::parse_as_sizes_attribute(DOM::Element const& return Length(100, Length::Type::Vw); } -// https://www.w3.org/TR/css-values-4/#parse-a-calculation +OwnPtr Parser::convert_to_calculation_node(CalcParsing::Node const& node) +{ + return node.visit( + [this](NonnullOwnPtr const& product_node) -> OwnPtr { + Vector> children; + children.ensure_capacity(product_node->children.size()); + + for (auto const& child : product_node->children) { + if (auto child_as_node = convert_to_calculation_node(child)) { + children.append(child_as_node.release_nonnull()); + } else { + return nullptr; + } + } + + return ProductCalculationNode::create(move(children)); + }, + [this](NonnullOwnPtr const& sum_node) -> OwnPtr { + Vector> children; + children.ensure_capacity(sum_node->children.size()); + + for (auto const& child : sum_node->children) { + if (auto child_as_node = convert_to_calculation_node(child)) { + children.append(child_as_node.release_nonnull()); + } else { + return nullptr; + } + } + + return SumCalculationNode::create(move(children)); + }, + [this](NonnullOwnPtr const& invert_node) -> OwnPtr { + if (auto child_as_node = convert_to_calculation_node(invert_node->child)) + return InvertCalculationNode::create(child_as_node.release_nonnull()); + return nullptr; + }, + [this](NonnullOwnPtr const& negate_node) -> OwnPtr { + if (auto child_as_node = convert_to_calculation_node(negate_node->child)) + return NegateCalculationNode::create(child_as_node.release_nonnull()); + return nullptr; + }, + [](Number const& number) -> OwnPtr { + return NumericCalculationNode::create(number); + }, + [](Dimension const& dimension) -> OwnPtr { + if (dimension.is_angle()) + return NumericCalculationNode::create(dimension.angle()); + if (dimension.is_frequency()) + return NumericCalculationNode::create(dimension.frequency()); + if (dimension.is_length()) + return NumericCalculationNode::create(dimension.length()); + if (dimension.is_percentage()) + return NumericCalculationNode::create(dimension.percentage()); + if (dimension.is_resolution()) + return NumericCalculationNode::create(dimension.resolution()); + if (dimension.is_time()) + return NumericCalculationNode::create(dimension.time()); + if (dimension.is_flex()) { + // https://www.w3.org/TR/css3-grid-layout/#fr-unit + // NOTE: values are not s (nor are they compatible with s, like some values), + // so they cannot be represented in or combined with other unit types in calc() expressions. + // FIXME: Flex is allowed in calc(), so figure out what this spec text means and how to implement it. + dbgln_if(CSS_PARSER_DEBUG, "Rejecting in calc()"); + return nullptr; + } + dbgln_if(CSS_PARSER_DEBUG, "Unrecognized dimension type in calc() expression: {}", dimension.to_string()); + return nullptr; + }, + [](CalculationNode::ConstantType const& constant_type) -> OwnPtr { + return ConstantCalculationNode::create(constant_type); + }, + [this](NonnullRawPtr const& component_value) -> OwnPtr { + // NOTE: This is the "process the leaf nodes" part of step 5 of https://drafts.csswg.org/css-values-4/#parse-a-calculation + // We divert a little from the spec: Rather than modify an existing tree of values, we construct a new one from that source tree. + // This lets us make CalculationNodes immutable. + + // 1. If leaf is a parenthesized simple block, replace leaf with the result of parsing a calculation from leaf’s contents. + if (component_value->is_block() && component_value->block().is_paren()) { + auto leaf_calculation = parse_a_calculation(component_value->block().value); + if (!leaf_calculation) + return nullptr; + + return leaf_calculation.release_nonnull(); + } + + // 2. If leaf is a math function, replace leaf with the internal representation of that math function. + // NOTE: All function tokens at this point should be math functions. + if (component_value->is_function()) { + auto const& function = component_value->function(); + auto leaf_calculation = parse_a_calc_function_node(function); + if (!leaf_calculation) + return nullptr; + + return leaf_calculation.release_nonnull(); + } + + // NOTE: If we get here, then we have a ComponentValue that didn't get replaced with something else, + // so the calc() is invalid. + dbgln_if(CSS_PARSER_DEBUG, "Leftover ComponentValue in calc tree! That probably means the syntax is invalid, but maybe we just didn't implement `{}` yet.", component_value->to_debug_string()); + return nullptr; + }, + [](CalcParsing::Operator const& op) -> OwnPtr { + dbgln_if(CSS_PARSER_DEBUG, "Leftover Operator {} in calc tree!", op.delim); + return nullptr; + }); +} + +// https://drafts.csswg.org/css-values-4/#parse-a-calculation OwnPtr Parser::parse_a_calculation(Vector const& original_values) { // 1. Discard any s from values. // 2. An item in values is an “operator” if it’s a with the value "+", "-", "*", or "/". Otherwise, it’s a “value”. - struct Operator { - char delim; - }; - using Value = Variant, Operator>; - Vector values; + + Vector values; for (auto const& value : original_values) { if (value.is(Token::Type::Whitespace)) continue; if (value.is(Token::Type::Delim)) { if (first_is_one_of(value.token().delim(), static_cast('+'), static_cast('-'), static_cast('*'), static_cast('/'))) { // NOTE: Sequential operators are invalid syntax. - if (!values.is_empty() && values.last().has()) + if (!values.is_empty() && values.last().has()) return nullptr; - values.append(Operator { static_cast(value.token().delim()) }); + values.append(CalcParsing::Operator { static_cast(value.token().delim()) }); continue; } } @@ -9175,41 +9245,22 @@ OwnPtr Parser::parse_a_calculation(Vector const if (value.is(Token::Type::Ident)) { auto maybe_constant = CalculationNode::constant_type_from_string(value.token().ident()); if (maybe_constant.has_value()) { - values.append({ ConstantCalculationNode::create(maybe_constant.value()) }); + values.append(maybe_constant.value()); continue; } } if (value.is(Token::Type::Number)) { - values.append({ NumericCalculationNode::create(value.token().number()) }); + values.append(value.token().number()); continue; } if (auto dimension = parse_dimension(value); dimension.has_value()) { - if (dimension->is_angle()) - values.append({ NumericCalculationNode::create(dimension->angle()) }); - else if (dimension->is_frequency()) - values.append({ NumericCalculationNode::create(dimension->frequency()) }); - else if (dimension->is_length()) - values.append({ NumericCalculationNode::create(dimension->length()) }); - else if (dimension->is_percentage()) - values.append({ NumericCalculationNode::create(dimension->percentage()) }); - else if (dimension->is_resolution()) - values.append({ NumericCalculationNode::create(dimension->resolution()) }); - else if (dimension->is_time()) - values.append({ NumericCalculationNode::create(dimension->time()) }); - else if (dimension->is_flex()) { - // https://www.w3.org/TR/css3-grid-layout/#fr-unit - // NOTE: values are not s (nor are they compatible with s, like some values), - // so they cannot be represented in or combined with other unit types in calc() expressions. - return nullptr; - } else { - VERIFY_NOT_REACHED(); - } + values.append(dimension.release_value()); continue; } - values.append({ UnparsedCalculationNode::create(value) }); + values.append(NonnullRawPtr { value }); } // If we have no values, the syntax is invalid. @@ -9217,15 +9268,15 @@ OwnPtr Parser::parse_a_calculation(Vector const return nullptr; // NOTE: If the first or last value is an operator, the syntax is invalid. - if (values.first().has() || values.last().has()) + if (values.first().has() || values.last().has()) return nullptr; // 3. Collect children into Product and Invert nodes. // For every consecutive run of value items in values separated by "*" or "/" operators: while (true) { Optional first_product_operator = values.find_first_index_if([](auto const& item) { - return item.template has() - && first_is_one_of(item.template get().delim, '*', '/'); + return item.template has() + && first_is_one_of(item.template get().delim, '*', '/'); }); if (!first_product_operator.has_value()) @@ -9235,12 +9286,12 @@ OwnPtr Parser::parse_a_calculation(Vector const auto end_of_run = first_product_operator.value() + 1; for (auto i = start_of_run + 1; i < values.size(); i += 2) { auto& item = values[i]; - if (!item.has()) { + if (!item.has()) { end_of_run = i - 1; break; } - auto delim = item.get().delim; + auto delim = item.get().delim; if (!first_is_one_of(delim, '*', '/')) { end_of_run = i - 1; break; @@ -9248,37 +9299,34 @@ OwnPtr Parser::parse_a_calculation(Vector const } // 1. For each "/" operator in the run, replace its right-hand value item rhs with an Invert node containing rhs as its child. - Vector> run_values; - run_values.append(move(values[start_of_run].get>())); + Vector run_values; + run_values.append(move(values[start_of_run])); for (auto i = start_of_run + 1; i <= end_of_run; i += 2) { - auto& operator_ = values[i].get().delim; + auto& operator_ = values[i].get().delim; auto& rhs = values[i + 1]; if (operator_ == '/') { - run_values.append(InvertCalculationNode::create(move(rhs.get>()))); + run_values.append(make(move(rhs))); continue; } VERIFY(operator_ == '*'); - run_values.append(move(rhs.get>())); + run_values.append(move(rhs)); } // 2. Replace the entire run with a Product node containing the value items of the run as its children. - auto product_node = ProductCalculationNode::create(move(run_values)); values.remove(start_of_run, end_of_run - start_of_run + 1); - values.insert(start_of_run, { move(product_node) }); + values.insert(start_of_run, make(move(run_values))); } // 4. Collect children into Sum and Negate nodes. - Optional> single_value; + Optional single_value; { // 1. For each "-" operator item in values, replace its right-hand value item rhs with a Negate node containing rhs as its child. for (auto i = 0u; i < values.size(); ++i) { auto& maybe_minus_operator = values[i]; - if (!maybe_minus_operator.has() || maybe_minus_operator.get().delim != '-') + if (!maybe_minus_operator.has() || maybe_minus_operator.get().delim != '-') continue; auto rhs_index = ++i; - auto& rhs = values[rhs_index]; - - NonnullOwnPtr negate_node = NegateCalculationNode::create(move(rhs.get>())); + auto negate_node = make(move(values[rhs_index])); values.remove(rhs_index); values.insert(rhs_index, move(negate_node)); } @@ -9286,77 +9334,31 @@ OwnPtr Parser::parse_a_calculation(Vector const // 2. If values has only one item, and it is a Product node or a parenthesized simple block, replace values with that item. if (values.size() == 1) { values.first().visit( - [&](ComponentValue& component_value) { + [&](ComponentValue const& component_value) { if (component_value.is_block() && component_value.block().is_paren()) - single_value = UnparsedCalculationNode::create(move(component_value)); + single_value = NonnullRawPtr { component_value }; }, - [&](NonnullOwnPtr& node) { - if (node->type() == CalculationNode::Type::Product) - single_value = move(node); + [&](NonnullOwnPtr& node) { + single_value = move(node); }, [](auto&) {}); } // Otherwise, replace values with a Sum node containing the value items of values as its children. if (!single_value.has_value()) { - values.remove_all_matching([](Value& value) { return value.has(); }); - Vector> value_items; - value_items.ensure_capacity(values.size()); - for (auto& value : values) { - if (value.has()) - continue; - value_items.unchecked_append(move(value.get>())); - } - single_value = SumCalculationNode::create(move(value_items)); + values.remove_all_matching([](CalcParsing::Node& value) { return value.has(); }); + single_value = make(move(values)); } } + VERIFY(single_value.has_value()); // 5. At this point values is a tree of Sum, Product, Negate, and Invert nodes, with other types of values at the leaf nodes. Process the leaf nodes. - // For every leaf node leaf in values: - bool parsing_failed_for_child_node = false; - single_value.value()->for_each_child_node([&](NonnullOwnPtr& node) { - if (node->type() != CalculationNode::Type::Unparsed) - return; - - auto& unparsed_node = static_cast(*node); - auto& component_value = unparsed_node.component_value(); - - // 1. If leaf is a parenthesized simple block, replace leaf with the result of parsing a calculation from leaf’s contents. - if (component_value.is_block() && component_value.block().is_paren()) { - auto leaf_calculation = parse_a_calculation(component_value.block().value); - if (!leaf_calculation) { - parsing_failed_for_child_node = true; - return; - } - node = leaf_calculation.release_nonnull(); - return; - } - - // 2. If leaf is a math function, replace leaf with the internal representation of that math function. - // NOTE: All function tokens at this point should be math functions. - else if (component_value.is_function()) { - auto& function = component_value.function(); - auto leaf_calculation = parse_a_calc_function_node(function); - if (!leaf_calculation) { - parsing_failed_for_child_node = true; - return; - } - - node = leaf_calculation.release_nonnull(); - return; - } - - // NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else. - // So, the calc() is invalid. - dbgln_if(CSS_PARSER_DEBUG, "Leftover UnparsedCalculationNode in calc tree! That probably means the syntax is invalid, but maybe we just didn't implement `{}` yet.", component_value.to_debug_string()); - parsing_failed_for_child_node = true; - return; - }); - - if (parsing_failed_for_child_node) + // NOTE: We process leaf nodes as part of this conversion. + auto calculation_tree = convert_to_calculation_node(*single_value); + if (!calculation_tree) return nullptr; // FIXME: 6. Return the result of simplifying a calculation tree from values. - return single_value.release_value(); + return calculation_tree.release_nonnull(); } bool Parser::has_ignored_vendor_prefix(StringView string) diff --git a/Libraries/LibWeb/CSS/Parser/Parser.h b/Libraries/LibWeb/CSS/Parser/Parser.h index 1a9367a55bc..289e3bd467f 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Libraries/LibWeb/CSS/Parser/Parser.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -34,6 +35,29 @@ namespace Web::CSS::Parser { class PropertyDependencyNode; +namespace CalcParsing { +struct Operator { + char delim; +}; +struct ProductNode; +struct SumNode; +struct InvertNode; +struct NegateNode; +using Node = Variant, NonnullOwnPtr, NonnullOwnPtr, NonnullOwnPtr, NonnullRawPtr>; +struct ProductNode { + Vector children; +}; +struct SumNode { + Vector children; +}; +struct InvertNode { + Node child; +}; +struct NegateNode { + Node child; +}; +} + class Parser { public: static Parser create(ParsingContext const&, StringView input, StringView encoding = "utf-8"sv); @@ -371,6 +395,7 @@ private: RefPtr parse_grid_area_shorthand_value(TokenStream&); RefPtr parse_grid_shorthand_value(TokenStream&); + OwnPtr convert_to_calculation_node(CalcParsing::Node const&); OwnPtr parse_a_calculation(Vector const&); ParseErrorOr> parse_complex_selector(TokenStream&, SelectorType); diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.cpp b/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.cpp index 21985586021..ec34b398e37 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.cpp @@ -366,14 +366,6 @@ CSSMathValue::CalculationResult SumCalculationNode::resolve(Optional&)> const& callback) -{ - for (auto& item : m_values) { - item->for_each_child_node(callback); - callback(item); - } -} - void SumCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}SUM:\n", "", indent); @@ -504,14 +496,6 @@ CSSMathValue::CalculationResult ProductCalculationNode::resolve(Optional&)> const& callback) -{ - for (auto& item : m_values) { - item->for_each_child_node(callback); - callback(item); - } -} - void ProductCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}PRODUCT:\n", "", indent); @@ -576,12 +560,6 @@ CSSMathValue::CalculationResult NegateCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void NegateCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}NEGATE:\n", "", indent); @@ -646,12 +624,6 @@ CSSMathValue::CalculationResult InvertCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void InvertCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}INVERT:\n", "", indent); @@ -734,14 +706,6 @@ CSSMathValue::CalculationResult MinCalculationNode::resolve(Optional&)> const& callback) -{ - for (auto& value : m_values) { - value->for_each_child_node(callback); - callback(value); - } -} - void MinCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}MIN:\n", "", indent); @@ -831,14 +795,6 @@ CSSMathValue::CalculationResult MaxCalculationNode::resolve(Optional&)> const& callback) -{ - for (auto& value : m_values) { - value->for_each_child_node(callback); - callback(value); - } -} - void MaxCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}MAX:\n", "", indent); @@ -939,16 +895,6 @@ CSSMathValue::CalculationResult ClampCalculationNode::resolve(Optional&)> const& callback) -{ - m_min_value->for_each_child_node(callback); - m_center_value->for_each_child_node(callback); - m_max_value->for_each_child_node(callback); - callback(m_min_value); - callback(m_center_value); - callback(m_max_value); -} - void ClampCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}CLAMP:\n", "", indent); @@ -1019,12 +965,6 @@ CSSMathValue::CalculationResult AbsCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void AbsCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ABS: {}\n", "", indent, to_string()); @@ -1092,12 +1032,6 @@ CSSMathValue::CalculationResult SignCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void SignCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}SIGN: {}\n", "", indent, to_string()); @@ -1237,12 +1171,6 @@ CSSMathValue::CalculationResult SinCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void SinCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}SIN: {}\n", "", indent, to_string()); @@ -1305,12 +1233,6 @@ CSSMathValue::CalculationResult CosCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void CosCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}COS: {}\n", "", indent, to_string()); @@ -1373,12 +1295,6 @@ CSSMathValue::CalculationResult TanCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void TanCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}TAN: {}\n", "", indent, to_string()); @@ -1441,12 +1357,6 @@ CSSMathValue::CalculationResult AsinCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void AsinCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ASIN: {}\n", "", indent, to_string()); @@ -1509,12 +1419,6 @@ CSSMathValue::CalculationResult AcosCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void AcosCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ACOS: {}\n", "", indent, to_string()); @@ -1577,12 +1481,6 @@ CSSMathValue::CalculationResult AtanCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void AtanCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ATAN: {}\n", "", indent, to_string()); @@ -1652,14 +1550,6 @@ CSSMathValue::CalculationResult Atan2CalculationNode::resolve(Optional&)> const& callback) -{ - m_y->for_each_child_node(callback); - m_x->for_each_child_node(callback); - callback(m_y); - callback(m_x); -} - void Atan2CalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ATAN2: {}\n", "", indent, to_string()); @@ -1725,14 +1615,6 @@ CSSMathValue::CalculationResult PowCalculationNode::resolve(Optional&)> const& callback) -{ - m_x->for_each_child_node(callback); - m_y->for_each_child_node(callback); - callback(m_x); - callback(m_y); -} - void PowCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}POW: {}\n", "", indent, to_string()); @@ -1791,12 +1673,6 @@ CSSMathValue::CalculationResult SqrtCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void SqrtCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}SQRT: {}\n", "", indent, to_string()); @@ -1876,14 +1752,6 @@ CSSMathValue::CalculationResult HypotCalculationNode::resolve(Optional&)> const& callback) -{ - for (auto& value : m_values) { - value->for_each_child_node(callback); - callback(value); - } -} - void HypotCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}HYPOT:\n", "", indent); @@ -1954,14 +1822,6 @@ CSSMathValue::CalculationResult LogCalculationNode::resolve(Optional&)> const& callback) -{ - m_x->for_each_child_node(callback); - m_y->for_each_child_node(callback); - callback(m_x); - callback(m_y); -} - void LogCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}LOG: {}\n", "", indent, to_string()); @@ -2020,12 +1880,6 @@ CSSMathValue::CalculationResult ExpCalculationNode::resolve(Optional&)> const& callback) -{ - m_value->for_each_child_node(callback); - callback(m_value); -} - void ExpCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}EXP: {}\n", "", indent, to_string()); @@ -2130,14 +1984,6 @@ CSSMathValue::CalculationResult RoundCalculationNode::resolve(Optional&)> const& callback) -{ - m_x->for_each_child_node(callback); - m_y->for_each_child_node(callback); - callback(m_x); - callback(m_y); -} - void RoundCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}ROUND: {}\n", "", indent, to_string()); @@ -2217,14 +2063,6 @@ CSSMathValue::CalculationResult ModCalculationNode::resolve(Optional&)> const& callback) -{ - m_x->for_each_child_node(callback); - m_y->for_each_child_node(callback); - callback(m_x); - callback(m_y); -} - void ModCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}MOD: {}\n", "", indent, to_string()); @@ -2302,14 +2140,6 @@ CSSMathValue::CalculationResult RemCalculationNode::resolve(Optional&)> const& callback) -{ - m_x->for_each_child_node(callback); - m_y->for_each_child_node(callback); - callback(m_x); - callback(m_y); -} - void RemCalculationNode::dump(StringBuilder& builder, int indent) const { builder.appendff("{: >{}}REM: {}\n", "", indent, to_string()); diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.h b/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.h index 762679c9632..25ff0ad0fb1 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/CSSMathValue.h @@ -264,7 +264,6 @@ public: virtual Optional determine_type(PropertyID) const = 0; virtual bool contains_percentage() const = 0; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const = 0; - virtual void for_each_child_node(Function&)> const&) = 0; virtual void dump(StringBuilder&, int indent) const = 0; virtual bool equals(CalculationNode const&) const = 0; @@ -286,7 +285,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override { } virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -306,7 +304,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -326,7 +323,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -346,7 +342,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -366,7 +361,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -386,7 +380,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -406,7 +399,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -426,7 +418,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -448,7 +439,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -468,7 +458,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -488,7 +477,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override { return false; } virtual CSSMathValue::CalculationResult resolve(Optional context, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override { } virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -508,7 +496,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -528,7 +515,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -548,7 +534,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -568,7 +553,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -588,7 +572,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -608,7 +591,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -628,7 +610,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -649,7 +630,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override { return false; } virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -670,7 +650,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override { return false; } virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -690,7 +669,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -710,7 +688,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override { return false; } virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -731,7 +708,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override { return false; } virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -751,7 +727,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -773,7 +748,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override; @@ -794,7 +768,6 @@ public: virtual Optional determine_type(PropertyID) const override; virtual bool contains_percentage() const override; virtual CSSMathValue::CalculationResult resolve(Optional, CSSMathValue::PercentageBasis const&) const override; - virtual void for_each_child_node(Function&)> const&) override; virtual void dump(StringBuilder&, int indent) const override; virtual bool equals(CalculationNode const&) const override;