Skip to content

Commit 4dfdca7

Browse files
mussorgskyAtkinsSJ
authored andcommitted
LibWeb: Handle <relative-size> values in the font-size CSS property
1 parent a551e02 commit 4dfdca7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,14 +1022,24 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
10221022
{ CSS::ValueID::XLarge, 1.5 },
10231023
{ CSS::ValueID::XxLarge, 2.0 },
10241024
{ CSS::ValueID::XxxLarge, 3.0 },
1025+
{ CSS::ValueID::Smaller, 0.8 },
1026+
{ CSS::ValueID::Larger, 1.25 },
10251027
};
1028+
10261029
auto const identifier = static_cast<IdentifierStyleValue const&>(*font_size).id();
1030+
1031+
// https://w3c.github.io/csswg-drafts/css-fonts/#valdef-font-size-relative-size
1032+
// TODO: If the parent element has a keyword font size in the absolute size keyword mapping table,
1033+
// larger may compute the font size to the next entry in the table,
1034+
// and smaller may compute the font size to the previous entry in the table.
10271035
if (identifier == CSS::ValueID::Smaller || identifier == CSS::ValueID::Larger) {
1028-
// FIXME: Should be based on parent element
1029-
} else {
1030-
auto const multiplier = absolute_size_mapping.get(identifier).value_or(1.0);
1031-
font_size_in_px *= multiplier;
1036+
if (parent_element && parent_element->computed_css_values()) {
1037+
font_size_in_px = parent_element->computed_css_values()->computed_font().pixel_metrics().size;
1038+
}
10321039
}
1040+
auto const multiplier = absolute_size_mapping.get(identifier).value_or(1.0);
1041+
font_size_in_px *= multiplier;
1042+
10331043
} else {
10341044
float root_font_size = root_element_font_size();
10351045

0 commit comments

Comments
 (0)