summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-15 19:39:33 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-15 19:40:06 +0100
commit30685a7714e1b18f7da48753769ac7ae0bc442c7 (patch)
tree6f41d189ba7b726ca152e7fe1597754308fec897 /Libraries/LibWeb
parent58bade25dd36c9eded4c8f1464f7032793f21b1c (diff)
downloadserenity-30685a7714e1b18f7da48753769ac7ae0bc442c7.zip
LibWeb: Add equals() for LengthStyleValue and ColorStyleValue
The default equals() does to_string() on both sides which is pretty silly when they are of the same type.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/CSS/Length.h10
-rw-r--r--Libraries/LibWeb/CSS/StyleValue.h14
2 files changed, 24 insertions, 0 deletions
diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h
index ec781aee6d..ff1d2897b0 100644
--- a/Libraries/LibWeb/CSS/Length.h
+++ b/Libraries/LibWeb/CSS/Length.h
@@ -154,6 +154,16 @@ public:
return String::format("[%g %s]", m_value, unit_name());
}
+ bool operator==(const Length& other) const
+ {
+ return m_type == other.m_type && m_value == other.m_value;
+ }
+
+ bool operator!=(const Length& other) const
+ {
+ return !(*this == other);
+ }
+
private:
float relative_length_to_px(const Layout::Node&) const;
diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h
index 52b724c57c..2fba93a988 100644
--- a/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValue.h
@@ -338,6 +338,13 @@ public:
virtual bool is_auto() const override { return m_length.is_auto(); }
+ virtual bool equals(const StyleValue& other) const override
+ {
+ if (type() != other.type())
+ return false;
+ return m_length == static_cast<const LengthStyleValue&>(other).m_length;
+ }
+
private:
explicit LengthStyleValue(const Length& length)
: StyleValue(Type::Length)
@@ -388,6 +395,13 @@ public:
String to_string() const override { return m_color.to_string(); }
Color to_color(const DOM::Document&) const override { return m_color; }
+ virtual bool equals(const StyleValue& other) const override
+ {
+ if (type() != other.type())
+ return false;
+ return m_color == static_cast<const ColorStyleValue&>(other).m_color;
+ }
+
private:
explicit ColorStyleValue(Color color)
: StyleValue(Type::Color)