diff --git a/Tests/LibWeb/Layout/expected/calc-font-size-with-percentages.txt b/Tests/LibWeb/Layout/expected/calc-font-size-with-percentages.txt new file mode 100644 index 00000000000..3273143216a --- /dev/null +++ b/Tests/LibWeb/Layout/expected/calc-font-size-with-percentages.txt @@ -0,0 +1,17 @@ +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 784x105.21875 children: not-inline + BlockContainer at (8,8) content-size 784x105.21875 children: inline + line 0 width: 500.8125, height: 52.40625, bottom: 52.40625, baseline: 40.59375 + frag 0 from TextNode start: 0, length: 20, rect: [8,8 500.8125x52.40625] + "i resolved enough of" + line 1 width: 406.40625, height: 52.8125, bottom: 105.21875, baseline: 40.59375 + frag 0 from TextNode start: 21, length: 16, rect: [8,60 406.40625x52.40625] + "percentages, no?" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x105.21875] + PaintableWithLines (BlockContainer
.test) [8,8 784x105.21875] + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/calc-font-size-with-percentages.html b/Tests/LibWeb/Layout/input/calc-font-size-with-percentages.html new file mode 100644 index 00000000000..66c32e5d882 --- /dev/null +++ b/Tests/LibWeb/Layout/input/calc-font-size-with-percentages.html @@ -0,0 +1,5 @@ +
i resolved enough of percentages, no?
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index f7470d5f7a6..b17ed0446b6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1764,7 +1764,11 @@ RefPtr StyleComputer::compute_font_for_style_values(DOM::Elemen } else if (font_size.is_length()) { maybe_length = font_size.as_length().length(); } else if (font_size.is_calculated()) { - maybe_length = font_size.as_calculated().resolve_length(length_resolution_context); + if (font_size.as_calculated().contains_percentage()) { + maybe_length = font_size.as_calculated().resolve_length_percentage(length_resolution_context, Length::make_px(parent_font_size())); + } else { + maybe_length = font_size.as_calculated().resolve_length(length_resolution_context); + } } if (maybe_length.has_value()) { font_size_in_px = maybe_length.value().to_px(length_resolution_context); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index 503d9e08378..ad3c00cf767 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -2371,7 +2371,17 @@ Optional CalculatedStyleValue::resolve_length(Layout::Node const& layout Optional CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, Length const& percentage_basis) const { - auto result = m_calculation->resolve(Length::ResolutionContext::for_layout_node(layout_node), percentage_basis); + return resolve_length_percentage(Length::ResolutionContext::for_layout_node(layout_node), percentage_basis); +} + +Optional CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, CSSPixels percentage_basis) const +{ + return resolve_length_percentage(Length::ResolutionContext::for_layout_node(layout_node), Length::make_px(percentage_basis)); +} + +Optional CalculatedStyleValue::resolve_length_percentage(Length::ResolutionContext const& resolution_context, Length const& percentage_basis) const +{ + auto result = m_calculation->resolve(resolution_context, percentage_basis); return result.value().visit( [&](Length const& length) -> Optional { @@ -2385,22 +2395,6 @@ Optional CalculatedStyleValue::resolve_length_percentage(Layout::Node co }); } -Optional CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, CSSPixels percentage_basis) const -{ - auto result = m_calculation->resolve(Length::ResolutionContext::for_layout_node(layout_node), Length::make_px(percentage_basis)); - - return result.value().visit( - [&](Length const& length) -> Optional { - return length; - }, - [&](Percentage const& percentage) -> Optional { - return Length::make_px(CSSPixels(percentage.value() * percentage_basis) / 100); - }, - [&](auto const&) -> Optional { - return {}; - }); -} - Optional CalculatedStyleValue::resolve_percentage() const { auto result = m_calculation->resolve({}, {}); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h index 58a59b8f135..137894b039c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h @@ -95,6 +95,7 @@ public: Optional resolve_length(Layout::Node const& layout_node) const; Optional resolve_length_percentage(Layout::Node const&, Length const& percentage_basis) const; Optional resolve_length_percentage(Layout::Node const&, CSSPixels percentage_basis) const; + Optional resolve_length_percentage(Length::ResolutionContext const&, Length const& percentage_basis) const; bool resolves_to_percentage() const { return m_resolved_type.matches_percentage(); } Optional resolve_percentage() const;