diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index 25230a9e33daf..d1a3953452bc9 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -2287,6 +2287,19 @@ Optional ComputedProperties::stroke(ColorResolutionContext const& colo return SVGPaint::from_style_value(value, color_resolution_context); } +LengthPercentage ComputedProperties::stroke_width() const +{ + auto const& value = property(PropertyID::StrokeWidth); + + if (value.is_number() || (value.is_calculated() && value.as_calculated().resolves_to_number())) { + // FIXME: Converting to pixels isn't really correct - values should be in "user units" + // https://svgwg.org/svg2-draft/coords.html#TermUserUnits + return CSS::Length::make_px(CSSPixels::nearest_value_for(number_from_style_value(value, {}))); + } + + return CSS::LengthPercentage::from_style_value(value); +} + Vector> ComputedProperties::stroke_dasharray() const { auto const& value = property(PropertyID::StrokeDasharray); @@ -2323,6 +2336,19 @@ Vector> ComputedProperties::stroke_dasharray() return dashes; } +LengthPercentage ComputedProperties::stroke_dashoffset() const +{ + auto const& value = property(PropertyID::StrokeDashoffset); + + if (value.is_number() || (value.is_calculated() && value.as_calculated().resolves_to_number())) { + // FIXME: Converting to pixels isn't really correct - values should be in "user units" + // https://svgwg.org/svg2-draft/coords.html#TermUserUnits + return CSS::Length::make_px(CSSPixels::nearest_value_for(number_from_style_value(value, {}))); + } + + return CSS::LengthPercentage::from_style_value(value); +} + StrokeLinecap ComputedProperties::stroke_linecap() const { auto const& value = property(PropertyID::StrokeLinecap); @@ -2529,15 +2555,15 @@ BorderImageData ComputedProperties::border_image() const .source = source.is_abstract_image() ? RefPtr { source.as_abstract_image() } : nullptr, .slice = { convert_slice(slice.top()), convert_slice(slice.right()), convert_slice(slice.bottom()), convert_slice(slice.left()) }, .width = expand_sides(property(PropertyID::BorderImageWidth), [](StyleValue const& value) -> BorderImageWidthValue { - if (value.is_number()) - return value.as_number().number(); + if (value.is_number() || (value.is_calculated() && value.as_calculated().resolves_to_number())) + return number_from_style_value(value, {}); if (value.to_keyword() == Keyword::Auto) return BorderImageWidthAuto {}; return LengthPercentage::from_style_value(value); }), .outset = expand_sides(property(PropertyID::BorderImageOutset), [](StyleValue const& value) -> BorderImageOutsetValue { - if (value.is_number()) - return value.as_number().number(); + if (value.is_number() || (value.is_calculated() && value.as_calculated().resolves_to_number())) + return number_from_style_value(value, {}); return Length::from_style_value(value, {}); }), .width_value_count = component_count(property(PropertyID::BorderImageWidth)), diff --git a/Libraries/LibWeb/CSS/ComputedProperties.h b/Libraries/LibWeb/CSS/ComputedProperties.h index b1fbfee32daef..e84b79b4ecfad 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.h +++ b/Libraries/LibWeb/CSS/ComputedProperties.h @@ -302,8 +302,10 @@ class ComputedProperties final : public RefCounted { float fill_opacity() const; Optional stroke(ColorResolutionContext const&) const; Vector> stroke_dasharray() const; + LengthPercentage stroke_dashoffset() const; StrokeLinecap stroke_linecap() const; StrokeLinejoin stroke_linejoin() const; + LengthPercentage stroke_width() const; VectorEffect vector_effect() const; double stroke_miterlimit() const; float stroke_opacity() const; diff --git a/Libraries/LibWeb/CSS/ComputedValues.cpp b/Libraries/LibWeb/CSS/ComputedValues.cpp index a8772749fcd87..a6a1ae45c86fd 100644 --- a/Libraries/LibWeb/CSS/ComputedValues.cpp +++ b/Libraries/LibWeb/CSS/ComputedValues.cpp @@ -2167,15 +2167,9 @@ NonnullRefPtr ComputedValues::create(ComputedProperties co if (!inherited_svg_adopted) computed_values.set_stroke(computed_style.stroke(color_resolution_context)); - auto const& stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth); - // FIXME: Converting to pixels isn't really correct - values should be in "user units" - // https://svgwg.org/svg2-draft/coords.html#TermUserUnits - if (!inherited_svg_adopted) { - if (stroke_width.is_number()) - computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_width.as_number().number()))); - else - computed_values.set_stroke_width(CSS::LengthPercentage::from_style_value(stroke_width)); - } + if (!inherited_svg_adopted) + computed_values.set_stroke_width(computed_style.stroke_width()); + if (!inherited_svg_adopted) { computed_values.set_paint_order(computed_style.paint_order()); auto const& paint_order = computed_style.property(PropertyID::PaintOrder); @@ -2224,15 +2218,8 @@ NonnullRefPtr ComputedValues::create(ComputedProperties co if (!inherited_svg_adopted) computed_values.set_stroke_dasharray(computed_style.stroke_dasharray()); - auto const& stroke_dashoffset = computed_style.property(CSS::PropertyID::StrokeDashoffset); - // FIXME: Converting to pixels isn't really correct - values should be in "user units" - // https://svgwg.org/svg2-draft/coords.html#TermUserUnits - if (!inherited_svg_adopted) { - if (stroke_dashoffset.is_number()) - computed_values.set_stroke_dashoffset(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_dashoffset.as_number().number()))); - else - computed_values.set_stroke_dashoffset(CSS::LengthPercentage::from_style_value(stroke_dashoffset)); - } + if (!inherited_svg_adopted) + computed_values.set_stroke_dashoffset(computed_style.stroke_dashoffset()); if (!inherited_svg_adopted) computed_values.set_stroke_linecap(computed_style.stroke_linecap()); diff --git a/Libraries/LibWeb/CSS/PercentageOr.h b/Libraries/LibWeb/CSS/PercentageOr.h index 92245f0634488..71a7b41d1dc0e 100644 --- a/Libraries/LibWeb/CSS/PercentageOr.h +++ b/Libraries/LibWeb/CSS/PercentageOr.h @@ -96,7 +96,7 @@ class LengthPercentage { static LengthPercentage from_style_value(NonnullRefPtr const& style_value) { - VERIFY(style_value->is_percentage() || style_value->is_length() || style_value->is_calculated()); + VERIFY(style_value->is_percentage() || style_value->is_length() || (style_value->is_calculated() && style_value->as_calculated().resolves_to_length())); return from_retained_data(StyleValueFFI::rust_style_value_retain(style_value->rust_style_value_data())); } diff --git a/Tests/LibWeb/Crash/CSS/calculated-number-border-image-outset.html b/Tests/LibWeb/Crash/CSS/calculated-number-border-image-outset.html new file mode 100644 index 0000000000000..3ae7bbc64900d --- /dev/null +++ b/Tests/LibWeb/Crash/CSS/calculated-number-border-image-outset.html @@ -0,0 +1,7 @@ + + +
diff --git a/Tests/LibWeb/Crash/CSS/calculated-number-border-image-width.html b/Tests/LibWeb/Crash/CSS/calculated-number-border-image-width.html new file mode 100644 index 0000000000000..83b1f37cf1a3a --- /dev/null +++ b/Tests/LibWeb/Crash/CSS/calculated-number-border-image-width.html @@ -0,0 +1,7 @@ + + +
diff --git a/Tests/LibWeb/Crash/CSS/calculated-number-stroke-dashoffset.html b/Tests/LibWeb/Crash/CSS/calculated-number-stroke-dashoffset.html new file mode 100644 index 0000000000000..4d1b823f0fb82 --- /dev/null +++ b/Tests/LibWeb/Crash/CSS/calculated-number-stroke-dashoffset.html @@ -0,0 +1,9 @@ + + + + + diff --git a/Tests/LibWeb/Crash/CSS/calculated-number-stroke-width.html b/Tests/LibWeb/Crash/CSS/calculated-number-stroke-width.html new file mode 100644 index 0000000000000..fe35ead732bbf --- /dev/null +++ b/Tests/LibWeb/Crash/CSS/calculated-number-stroke-width.html @@ -0,0 +1,9 @@ + + + + +