Преглед на файлове

LibWeb: Add equals() override to a bunch of StyleValue subclasses

The less we fall back to string-based equality testing, the better.
Andreas Kling преди 3 години
родител
ревизия
7a82a6dfe8
променени са 1 файла, в които са добавени 45 реда и са изтрити 0 реда
  1. 45 0
      Userland/Libraries/LibWeb/CSS/StyleValue.h

+ 45 - 0
Userland/Libraries/LibWeb/CSS/StyleValue.h

@@ -590,6 +590,14 @@ public:
 
 
     virtual String to_string() const override;
     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<BackgroundRepeatStyleValue const&>(other);
+        return m_repeat_x == other_value.m_repeat_x && m_repeat_y == other_value.m_repeat_y;
+    }
+
 private:
 private:
     BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y)
     BackgroundRepeatStyleValue(Repeat repeat_x, Repeat repeat_y)
         : StyleValue(Type::BackgroundRepeat)
         : StyleValue(Type::BackgroundRepeat)
@@ -616,6 +624,14 @@ public:
 
 
     virtual String to_string() const override;
     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<BackgroundSizeStyleValue const&>(other);
+        return m_size_x == other_value.m_size_x && m_size_y == other_value.m_size_y;
+    }
+
 private:
 private:
     BackgroundSizeStyleValue(LengthPercentage size_x, LengthPercentage size_y)
     BackgroundSizeStyleValue(LengthPercentage size_x, LengthPercentage size_y)
         : StyleValue(Type::BackgroundSize)
         : StyleValue(Type::BackgroundSize)
@@ -720,6 +736,19 @@ public:
 
 
     virtual String to_string() const override;
     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<BoxShadowStyleValue const&>(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:
 private:
     explicit BoxShadowStyleValue(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, BoxShadowPlacement placement)
     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)
         : StyleValue(Type::BoxShadow)
@@ -1639,6 +1668,22 @@ public:
 
 
     virtual String to_string() const override;
     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<StyleValueList const&>(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:
 private:
     StyleValueList(NonnullRefPtrVector<StyleValue>&& values, Separator separator)
     StyleValueList(NonnullRefPtrVector<StyleValue>&& values, Separator separator)
         : StyleValue(Type::ValueList)
         : StyleValue(Type::ValueList)