From ae9eaeffc407cff6bacc52b321b650ba2365d30a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 20 Sep 2023 12:30:58 +0100 Subject: [PATCH] LibWeb: Remove unnecessary code from sided border shorthand expansion I'm sure at some point we made use of `Edge::All` and this made sense, but now it's just overly verbose. --- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 43 ++++--------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 54dd20505f..cf2ff30997 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -351,19 +351,6 @@ static void sort_matching_rules(Vector& matching_rules) }); } -enum class Edge { - Top, - Right, - Bottom, - Left, - All, -}; - -static bool contains(Edge a, Edge b) -{ - return a == b || b == Edge::All; -} - static void set_property_expanding_shorthands(StyleProperties& style, CSS::PropertyID property_id, StyleValue const& value, DOM::Document& document, CSS::CSSStyleDeclaration const* declaration, StyleProperties::PropertyValues const& properties_for_revert) { auto set_longhand_property = [&](CSS::PropertyID property_id, StyleValue const& value) { @@ -572,45 +559,31 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope || property_id == CSS::PropertyID::BorderBottom || property_id == CSS::PropertyID::BorderLeft) { - Edge edge = Edge::All; - switch (property_id) { - case CSS::PropertyID::BorderTop: - edge = Edge::Top; - break; - case CSS::PropertyID::BorderRight: - edge = Edge::Right; - break; - case CSS::PropertyID::BorderBottom: - edge = Edge::Bottom; - break; - case CSS::PropertyID::BorderLeft: - edge = Edge::Left; - break; - default: - break; - } - if (value.is_border()) { auto const& border = value.as_border(); - if (contains(Edge::Top, edge)) { + if (property_id == CSS::PropertyID::BorderTop) { set_longhand_property(PropertyID::BorderTopWidth, border.border_width()); set_longhand_property(PropertyID::BorderTopStyle, border.border_style()); set_longhand_property(PropertyID::BorderTopColor, border.border_color()); + return; } - if (contains(Edge::Right, edge)) { + if (property_id == CSS::PropertyID::BorderRight) { set_longhand_property(PropertyID::BorderRightWidth, border.border_width()); set_longhand_property(PropertyID::BorderRightStyle, border.border_style()); set_longhand_property(PropertyID::BorderRightColor, border.border_color()); + return; } - if (contains(Edge::Bottom, edge)) { + if (property_id == CSS::PropertyID::BorderBottom) { set_longhand_property(PropertyID::BorderBottomWidth, border.border_width()); set_longhand_property(PropertyID::BorderBottomStyle, border.border_style()); set_longhand_property(PropertyID::BorderBottomColor, border.border_color()); + return; } - if (contains(Edge::Left, edge)) { + if (property_id == CSS::PropertyID::BorderLeft) { set_longhand_property(PropertyID::BorderLeftWidth, border.border_width()); set_longhand_property(PropertyID::BorderLeftStyle, border.border_style()); set_longhand_property(PropertyID::BorderLeftColor, border.border_color()); + return; } return; }