Skip to content

Commit

Permalink
WIP: Bring percentage handling up to date with spec - INCOMPLETE!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
AtkinsSJ committed Dec 12, 2024
1 parent 39b3e95 commit f817f28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions Libraries/LibWeb/CSS/CSSNumericType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,22 @@ Optional<CSSNumericType> CSSNumericType::consistent_type(CSSNumericType const& o
// https://drafts.css-houdini.org/css-typed-om-1/#apply-the-percent-hint
void CSSNumericType::apply_percent_hint(BaseType hint)
{
// To apply the percent hint hint to a type, perform the following steps:
// To apply the percent hint hint to a type without a percent hint, perform the following steps:

// 1. If type doesn’t contain hint, set type[hint] to 0.
// 1. Set type’s percent hint to hint,
set_percent_hint(hint);

// 2. If type doesn’t contain hint, set type[hint] to 0.
if (!exponent(hint).has_value())
set_exponent(hint, 0);

// 2. If type contains "percent", add type["percent"] to type[hint], then set type["percent"] to 0.
if (exponent(BaseType::Percent).has_value()) {
// 3. If hint is anything other than "percent", and type contains "percent", add type["percent"] to type[hint], then set type["percent"] to 0.
if (hint != BaseType::Percent && exponent(BaseType::Percent).has_value()) {
set_exponent(hint, exponent(BaseType::Percent).value() + exponent(hint).value());
set_exponent(BaseType::Percent, 0);
}

// 3. Set type’s percent hint to hint.
// 4. Set type’s percent hint to hint.
set_percent_hint(hint);
}

Expand Down
8 changes: 5 additions & 3 deletions Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ NonnullOwnPtr<NumericCalculationNode> NumericCalculationNode::create(NumericValu
// If, in the context in which the math function containing this calculation is placed,
// <percentage>s are resolved relative to another type of value (such as in width,
// where <percentage> is resolved against a <length>), and that other type is not <number>,
// the type is determined as the other type.
// the type is determined as the other type, but with a percent hint set to that other type.
if (percentage_resolved_type.has_value() && percentage_resolved_type != ValueType::Number && percentage_resolved_type != ValueType::Percentage) {
auto base_type = CSSNumericType::base_type_from_value_type(*percentage_resolved_type);
VERIFY(base_type.has_value());
return CSSNumericType { base_type.value(), 1 };
auto result = CSSNumericType { base_type.value(), 1 };
result.set_percent_hint(base_type);
return result;
}

// Otherwise, the type is «[ "percent" → 1 ]».
// Otherwise, the type is «[ "percent" → 1 ]», with a percent hint of "percent".
return CSSNumericType { CSSNumericType::BaseType::Percent, 1 };
});
// In all cases, the associated percent hint is null.
Expand Down

0 comments on commit f817f28

Please sign in to comment.