LibWeb/CSS: Improve parsing of length percentage values for transforms

This commit is contained in:
implicitfield 2024-01-09 12:39:17 +04:00 committed by Andreas Kling
parent 480cbd9126
commit c994326d5a
4 changed files with 33 additions and 2 deletions

View file

@ -0,0 +1,15 @@
<!doctype html><style>
* { outline: 1px solid black; }
html { background: white; }
body {
background: pink;
padding: 32px;
width: 200px;
}
div {
background: orange;
transform: translate(-26px, -25px);
width: 50px;
height: 50px;
}
</style><body><div>

View file

@ -0,0 +1,16 @@
<!doctype html>
<link rel="match" href="reference/transform-calc-length-percentage-ref.html" /><style>
* { outline: 1px solid black; }
html { background: white; }
body {
background: pink;
padding: 32px;
width: 200px;
}
div {
background: orange;
transform: translate(calc(-50% - 1px), -50%);
width: 50px;
height: 50px;
}
</style><body><div>

View file

@ -5095,7 +5095,7 @@ RefPtr<StyleValue> Parser::parse_transform_value(TokenStream<ComponentValue>& to
break;
}
case TransformFunctionParameterType::LengthPercentage: {
if (maybe_calc_value && maybe_calc_value->resolves_to_length()) {
if (maybe_calc_value && maybe_calc_value->resolves_to_length_percentage()) {
values.append(maybe_calc_value.release_nonnull());
} else {
auto dimension_value = parse_dimension_value(value);

View file

@ -426,7 +426,7 @@ Vector<CSS::Transformation> StyleProperties::transformations_for_style_value(Sty
for (auto& transformation_value : transformation_style_value.values()) {
if (transformation_value->is_calculated()) {
auto& calculated = transformation_value->as_calculated();
if (calculated.resolves_to_length()) {
if (calculated.resolves_to_length_percentage()) {
values.append(CSS::LengthPercentage { calculated });
} else if (calculated.resolves_to_percentage()) {
values.append({ calculated.resolve_percentage().value() });