From 7a82a6dfe8e8510a4312bcc29361e542955c63a0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 14 Mar 2022 00:23:58 +0100 Subject: [PATCH] LibWeb: Add equals() override to a bunch of StyleValue subclasses The less we fall back to string-based equality testing, the better. --- Userland/Libraries/LibWeb/CSS/StyleValue.h | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index c3a02435d1..078c32c03d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -590,6 +590,14 @@ public: virtual String to_string() const override; + virtual bool equals(StyleValue const& other) const override + { + if (type() != other.type()) + return false; + auto& other_value = static_cast(other); + return m_repeat_x == other_value.m_repeat_x && m_repeat_y == other_value.m_repeat_y; + } + private: BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y) : StyleValue(Type::BackgroundRepeat) @@ -616,6 +624,14 @@ public: virtual String to_string() const override; + virtual bool equals(StyleValue const& other) const override + { + if (type() != other.type()) + return false; + auto& other_value = static_cast(other); + return m_size_x == other_value.m_size_x && m_size_y == other_value.m_size_y; + } + private: BackgroundSizeStyleValue(LengthPercentage size_x, LengthPercentage size_y) : StyleValue(Type::BackgroundSize) @@ -720,6 +736,19 @@ public: virtual String to_string() const override; + virtual bool equals(StyleValue const& other) const override + { + if (type() != other.type()) + return false; + auto& other_value = static_cast(other); + return m_color == other_value.m_color + && m_offset_x == other_value.m_offset_x + && m_offset_y == other_value.m_offset_y + && m_blur_radius == other_value.m_blur_radius + && m_spread_distance == other_value.m_spread_distance + && m_placement == other_value.m_placement; + } + private: explicit BoxShadowStyleValue(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, BoxShadowPlacement placement) : StyleValue(Type::BoxShadow) @@ -1639,6 +1668,22 @@ public: virtual String to_string() const override; + virtual bool equals(StyleValue const& other) const override + { + if (type() != other.type()) + return false; + auto& other_value = static_cast(other); + if (m_separator != other_value.m_separator) + return false; + if (m_values.size() != other_value.m_values.size()) + return false; + for (size_t i = 0; i < m_values.size(); ++i) { + if (!m_values[i].equals(other_value.m_values[i])) + return false; + } + return true; + } + private: StyleValueList(NonnullRefPtrVector&& values, Separator separator) : StyleValue(Type::ValueList)