From 41e37f00795920686fad7b211381905618fb345a Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 17 Sep 2024 17:51:48 +0200 Subject: [PATCH] LibWeb: Use correct resolved type for round() CSS function Function is defined as `round(?, A, B?)` With this change resolved type is `typeof(resolve(A))`, instead of `typeof(A)`. For example `round(up, 20%, 1px)` with 200px percentage basis is now correctly resolved in 40px instead of 40%. Progress on https://www.notion.so/ landing page. --- .../css-round-function-with-percentage-value.txt | 15 +++++++++++++++ ...css-round-function-with-percentage-value.html | 11 +++++++++++ .../CSS/StyleValues/CalculatedStyleValue.cpp | 16 +++++++++++++++- .../CSS/StyleValues/CalculatedStyleValue.h | 2 ++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/css-round-function-with-percentage-value.txt create mode 100644 Tests/LibWeb/Layout/input/css-round-function-with-percentage-value.html diff --git a/Tests/LibWeb/Layout/expected/css-round-function-with-percentage-value.txt b/Tests/LibWeb/Layout/expected/css-round-function-with-percentage-value.txt new file mode 100644 index 00000000000..e575f96c238 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/css-round-function-with-percentage-value.txt @@ -0,0 +1,15 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x17 children: not-inline + BlockContainer at (8,8) content-size 200x17 children: not-inline + BlockContainer at (48,8) content-size 100x17 children: inline + frag 0 from TextNode start: 0, length: 1, rect: [48,8 6.34375x17] baseline: 13.296875 + "1" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x17] + PaintableWithLines (BlockContainer
.wrapper) [8,8 200x17] + PaintableWithLines (BlockContainer
.box) [8,8 140x17] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/css-round-function-with-percentage-value.html b/Tests/LibWeb/Layout/input/css-round-function-with-percentage-value.html new file mode 100644 index 00000000000..9d92ca9575c --- /dev/null +++ b/Tests/LibWeb/Layout/input/css-round-function-with-percentage-value.html @@ -0,0 +1,11 @@ + +
1
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index b3416439abc..235b6f54d43 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -2079,7 +2079,6 @@ bool RoundCalculationNode::contains_percentage() const CalculatedStyleValue::CalculationResult RoundCalculationNode::resolve(Optional context, CalculatedStyleValue::PercentageBasis const& percentage_basis) const { - auto resolved_type = m_x->resolved_type().value(); auto node_a = m_x->resolve(context, percentage_basis); auto node_b = m_y->resolve(context, percentage_basis); @@ -2089,6 +2088,8 @@ CalculatedStyleValue::CalculationResult RoundCalculationNode::resolve(Optional