Skip to content

Commit

Permalink
LibWeb/CSS: Improve parsing of length percentage values for transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
implicitfield authored and awesomekling committed Jan 9, 2024
1 parent 480cbd9 commit c994326
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions Tests/LibWeb/Ref/transform-calc-length-percentage.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down

0 comments on commit c994326

Please sign in to comment.