summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout/Node.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-16 12:28:14 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-16 22:30:33 +0200
commit3964b81d2b5458c0c4fb102929d3aae61f86feed (patch)
treef83daf24fd26eeb42544edc2dfc916a649e4c50f /Userland/Libraries/LibWeb/Layout/Node.cpp
parent2c8c56684bdf9e7716b21e7e133f37db2da24308 (diff)
downloadserenity-3964b81d2b5458c0c4fb102929d3aae61f86feed.zip
LibWeb: Add for CSS `fill/stroke/stroke-color` properties for SVG
In the spec, `fill` and `stroke` are supposed to be a shorthands for various properties. But since the spec is still a working draft, and neither Firefox or Chrome support the `fill-color` or `stroke-color` properties, we'll stick with `fill` and `stroke` as simple colors for now. Also, note that SVG expects things in "user units", and we are assuming that 1px = 1 user unit for now.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/Node.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index b8205cb667..b1ee4196f7 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -360,6 +360,19 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
do_border_style(computed_values.border_top(), CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor, CSS::PropertyID::BorderTopStyle);
do_border_style(computed_values.border_right(), CSS::PropertyID::BorderRightWidth, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightStyle);
do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
+
+ if (auto fill = specified_style.property(CSS::PropertyID::Fill); fill.has_value())
+ computed_values.set_fill(fill.value()->to_color(document()));
+ if (auto stroke = specified_style.property(CSS::PropertyID::Stroke); stroke.has_value())
+ computed_values.set_stroke(stroke.value()->to_color(document()));
+ if (auto stroke_width = specified_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
+ // FIXME: Converting to pixels isn't really correct - values should be in "user units"
+ // https://svgwg.org/svg2-draft/coords.html#TermUserUnits
+ if (stroke_width.value()->is_numeric())
+ computed_values.set_stroke_width(CSS::Length::make_px(static_cast<CSS::NumericStyleValue const&>(*stroke_width.value()).value()));
+ else
+ computed_values.set_stroke_width(stroke_width.value()->to_length());
+ }
}
void Node::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned)