From 586a7dca889f6a0346d3dd1f557b68a243f88312 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 24 Nov 2022 21:34:28 +0100 Subject: [PATCH] LibWeb: Support special border width identifiers Previously identifiers were resolved to zero length. This could be seen when a border declaration doesn't have specified width (e.g. `border: solid`), as the initial border width is 'medium'. The spec doesn't specify what the identifiers should really resolve to, but it gives us some example values and that's what I've used here. :^) Spec link: https://www.w3.org/TR/css-backgrounds-3/#border-width --- Userland/Libraries/LibWeb/Layout/Node.cpp | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index d2dd45beb0c..65643c1e57d 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -543,10 +543,33 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // specified first, so it's far from ideal. border.color = computed_style.color_or_fallback(color_property, *this, computed_values.color()); border.line_style = computed_style.line_style(style_property).value_or(CSS::LineStyle::None); - if (border.line_style == CSS::LineStyle::None) + if (border.line_style == CSS::LineStyle::None) { border.width = 0; - else - border.width = computed_style.length_or_fallback(width_property, CSS::Length::make_px(0)).to_px(*this); + } else { + auto resolve_border_width = [&]() { + auto value = computed_style.property(width_property); + if (value->is_calculated()) + return CSS::Length::make_calculated(value->as_calculated()).to_px(*this); + if (value->has_length()) + return value->to_length().to_px(*this); + if (value->is_identifier()) { + // FIXME: These values should depend on something, e.g. a font size. + switch (value->to_identifier()) { + case CSS::ValueID::Thin: + return 1.0f; + case CSS::ValueID::Medium: + return 3.0f; + case CSS::ValueID::Thick: + return 5.0f; + default: + VERIFY_NOT_REACHED(); + } + } + VERIFY_NOT_REACHED(); + }; + + border.width = resolve_border_width(); + } }; do_border_style(computed_values.border_left(), CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftStyle);