summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-18 17:01:15 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-20 00:04:10 +0100
commit0162ca912b58d5c7fbe8f8c75768d4819689a0a8 (patch)
treec1ca1615c665be4e0a61bc108d7da2945c96566f /Userland/Libraries/LibWeb
parentc8409cd58d356ded914b961cc5744999a927e1be (diff)
downloadserenity-0162ca912b58d5c7fbe8f8c75768d4819689a0a8.zip
LibWeb: Handle percentage font sizes
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 0f5180c2b5..58adffc755 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -755,21 +755,23 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
font_metrics = Gfx::FontDatabase::default_font().metrics('M');
Optional<Length> maybe_length;
- if (font_size->is_length()) {
- maybe_length = font_size->to_length();
- if (maybe_length->is_percentage()) {
- auto parent_font_size = size;
- if (element && element->parent_element() && element->parent_element()->layout_node() && element->parent_element()->specified_css_values()) {
- auto value = element->parent_element()->specified_css_values()->property(CSS::PropertyID::FontSize).value();
- if (value->is_length()) {
- auto length = static_cast<LengthStyleValue const&>(*value).to_length();
- if (length.is_absolute() || length.is_relative())
- parent_font_size = length.to_px(viewport_rect, font_metrics, root_font_size);
- }
+ if (font_size->is_percentage()) {
+ // Percentages refer to parent element's font size
+ auto percentage = font_size->as_percentage().percentage();
+ auto parent_font_size = size;
+ if (element && element->parent_element() && element->parent_element()->layout_node() && element->parent_element()->specified_css_values()) {
+ auto value = element->parent_element()->specified_css_values()->property(CSS::PropertyID::FontSize).value();
+ if (value->is_length()) {
+ auto length = static_cast<LengthStyleValue const&>(*value).to_length();
+ if (length.is_absolute() || length.is_relative())
+ parent_font_size = length.to_px(viewport_rect, font_metrics, root_font_size);
}
-
- maybe_length = Length::make_px(maybe_length->raw_value() / 100.0f * (parent_font_size));
}
+ maybe_length = Length::make_px(percentage.as_fraction() * parent_font_size);
+
+ } else if (font_size->is_length()) {
+ maybe_length = font_size->to_length();
+
} else if (font_size->is_calculated()) {
Length length = Length(0, Length::Type::Calculated);
length.set_calculated_style(verify_cast<CalculatedStyleValue>(font_size.ptr()));