mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
LibWeb/CSS: Use CSSNumericType for CalculationResult's numeric type
When we originally implemented calc(), the result of a calculation was guaranteed to be a single CSS type like a Length or Angle. However, CSS Values 4 now allows more complex type arithmetic, which is represented by the CSSNumericType class. Using that directly makes us more correct, and allows us to remove a large amount of now ad-hoc code. Unfortunately this is a large commit but the changes it makes are interconnected enough that doing one at a time causes test regressions. In no particular order: - Update our "determine the type of a calculation" code to match the newest spec, which sets percent hints in a couple more cases. (One of these we're skipping for now, I think it fails because of the FIXMEs in CSSNumericType::matches_foo().) - Make the generated math-function-parsing code aware of the difference between arguments being the same type, and being "consistent" types, for each function. Otherwise those extra percent hints would cause them to fail validation incorrectly. - Use the CSSNumericType as the type for the CalculationResult. - Calculate and assign each math function's type in its constructor, instead of calculating it repeatedly on-demand. The `CalculationNode::resolved_type()` method is now entirely unused and has been removed.
This commit is contained in:
parent
8d40550478
commit
eb11c35640
Notes:
github-actions[bot]
2024-12-21 17:15:19 +00:00
Author: https://github.com/AtkinsSJ
Commit: eb11c35640
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2966
7 changed files with 446 additions and 1168 deletions
|
@ -1924,7 +1924,7 @@ RefPtr<CalculatedStyleValue> Parser::parse_calculated_value(ComponentValue const
|
|||
if (!function_node)
|
||||
return nullptr;
|
||||
|
||||
auto function_type = function_node->determine_type(m_context.current_property_id());
|
||||
auto function_type = function_node->numeric_type();
|
||||
if (!function_type.has_value())
|
||||
return nullptr;
|
||||
|
||||
|
@ -1936,7 +1936,7 @@ OwnPtr<CalculationNode> Parser::parse_a_calc_function_node(Function const& funct
|
|||
if (function.name.equals_ignoring_ascii_case("calc"sv))
|
||||
return parse_a_calculation(function.value);
|
||||
|
||||
if (auto maybe_function = parse_math_function(m_context.current_property_id(), function))
|
||||
if (auto maybe_function = parse_math_function(function))
|
||||
return maybe_function;
|
||||
|
||||
return nullptr;
|
||||
|
@ -9158,15 +9158,18 @@ OwnPtr<CalculationNode> Parser::convert_to_calculation_node(CalcParsing::Node co
|
|||
[](Number const& number) -> OwnPtr<CalculationNode> {
|
||||
return NumericCalculationNode::create(number);
|
||||
},
|
||||
[](Dimension const& dimension) -> OwnPtr<CalculationNode> {
|
||||
[this](Dimension const& dimension) -> OwnPtr<CalculationNode> {
|
||||
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_percentage()) {
|
||||
// FIXME: Figure this out in non-property contexts
|
||||
auto percentage_resolved_type = property_resolves_percentages_relative_to(m_context.current_property_id());
|
||||
return NumericCalculationNode::create(dimension.percentage(), percentage_resolved_type);
|
||||
}
|
||||
if (dimension.is_resolution())
|
||||
return NumericCalculationNode::create(dimension.resolution());
|
||||
if (dimension.is_time())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue